Loops n Strings n Things - Part 3 |
Released 19/9-2002 |
Written by VerticalE |
||||
Required reading: Hello DNA!, Variables Explained - Part 1 & 2, Loops n String n Things - Part 1 & 2 | ||||||
Since you already know everything besides the "while(loop == true)"
sentence, we are gonna jump straight to that and explain it in detail. Read
the sentence out loud, and I think you'll get the point; "while loop is
true". We can add a few words here and there, and it will make the sentence
more readable; "loop the code in the codeblock while the loop variable has
the value of true". As long as the statement in the parantheses next to
while is true, the codeblock will run.
As you can see, the statement "loop == 12345" is true when the while-loop
starts. In fact, it will loop forever, as the value of the loop variable
never changes in the source. So how do you stop the loop from looping?
That's right, make the while-statement false! Examine the following example:
You start by saying "loop this codeblock for as long as the value of the
variable loop is less than 10. With each time the loop loops, the loop value
gets incremented, until it reaches the value of 10. Then, the while-loop
breaks, and the application continues to the next pieces of code - in this
case by quitting the application and returning the value 0.
The above example will only run once. If the value of the variable loop
was 12345, the loop would run indefinately. |