Game Development Reference
In-Depth Information
4.
The conditional statement. As long as the condition is met, the loop
statement block will be executed. If the condition is not met, the loop is
terminated and program execution jumps to the statement that follows the
loop, in this case the closing braces of the Start() function.
A semicolon separates the second and third components of the for
statement.
5.
The increment of the loop. This could be written as i = i + 1 , or even i += 1 ,
but the increment operator ++ means to add 1 and is a nice shorthand notation.
Here 1 is added to the index variable before it is evaluated by the conditional
statement in the next iteration of the for loop. Similarly, the index variable can
also be decremented using the decrement operator -- (or -= ).
6.
Open brace for the body of the for loop.
7.
8.
The statement block that contains the code to be executed on each iteration
of the for loop.
Close brace for the body of the for loop. Like a function, the for loop ends
with the close brace rather than a semicolon.
9.
Run your script, and you'll see that you have four target statements reflecting the counting-from-zero
effect (Figure 2-28 ).
Figure 2-28. For loop output to the Console panel
The while Loop
The while loop gives you more flexibility because it will loop any number of times as long as the
conditional results with true .
Change your code to the following:
#pragma strict
var numberOfTires : int = 0;
 
Search WWH ::




Custom Search