Game Development Reference
In-Depth Information
True
Looping with While Statements
The while statement marks the beginning of a loop. Sometimes in our programs, we
want the program to do something over and over again. When the execution reaches a
while statement, it evaluates the condition next to the while keyword. If the condition
evaluates to True , the execution moves inside the while-block. (In our program, the while-
block begins on line 13.) If the condition evaluates to False , the execution moves all the
way past the while-block. (In our program, the first line after the while-block is line 28.)
12. while guessesTaken < 6:
Figure 4-2: The while loop's condition.
Figure 4-2 shows how the execution flows depending on the condition. If the condition
evaluates to True (which it does the first time, because the value of guessesTaken is
0 ), execution will enter the while-block at line 13 and keep going down. Once the program
reaches the end of the while-block, instead of going down to the next line, it jumps back up
to the while statement's line (line 12). It then re-evaluates the condition, and if it is True
 
Search WWH ::




Custom Search