Finite while loops Loops have been used extensively in every example. The loop was always looping while infinitely using This was used to simplify things but is BrainPad.Looping. BrainPad.Looping just a value internally. In other words, the loop will run while something is true while true and since we have passed it the value then it will loop forever. true Is the statement in Example 22 true? 1 = 1 Example 22 This statement asks if 1 equals 1 and the answer is yes, so it’s true. – Now we can make a loop, loop forever using this statement (Example 23). while public class Program { public void BrainPadSetup() { int count = 0; while (1 == 1) { count = count + 1; " + count); BrainPad.Wait.Seconds(0.2); } } public void BrainPadLoop() { // Declared but not used } } Example 23 Here we use the statement to keep the loop running forever. 1 == 1 while – It should be noted clearly that we used and not in the statement. The single == = while = is used to set a value (Example 24), not compare them (Example 25). int = 10; Example 24 This code sets to 10. count –
Finite while loops Loops have been used extensively in every example. The while loop was always looping infinitely using BrainPad.Looping. This was used to simplify things but BrainPad.Looping is just a true value internally. In other words, the while loop will run while something is true and since we have passed it the value true then it will loop forever. Is the statement in Example 22 true? 1 = 1 Example 22 – This statement asks if 1 equals 1 and the answer is yes, so it’s true. Now we can make a while loop, loop forever using this statement (Example 23). public class Program { public void BrainPadSetup() { int count = 0; while (1 == 1) { count = count + 1; " + count); BrainPad.Wait.Seconds(0.2); } } public void BrainPadLoop() { // Declared but not used } } Example 23 – Here we use the statement 1 == 1 to keep the while loop running forever. It should be noted clearly that we used == and not = in the while statement. The single = is used to set a value (Example 24), not compare them (Example 25). int = 10; Example 24 – This code sets count to 10.
BrainPad_CS_VariablesAndNestedStatements.docx