| NWN2 Scripting. |
Simulation Training. Introduction Home First Program Seeing Results Variables and Data Types Comments Functions Data Conversion Random Numbers Concatenation Arithmetic Operators Compound Assignments One More or Less Precedence Relational Operators The Open Branch The Closed Branch Logical AND Logical OR Compound Statements ELSE If Switch Case The ? Operator The for Loop The while Loop The do while Loop Introduction to Functions Passing Values Passing Multiple Values Multiple Functions Simplifying Functions TRUE/fALSE Conditions Return Values Setting Global Variables Getting Global Variables Setting Local Variables Getting Local Variables WayPoints Introduction Static Waypoint Sets Dynamic Waypoint Sets Dynamic WP Cycles Input Output |
The do while loopThe do while loop is structured simular to the while loop, the difference being that the test condition is evaluated after the loop is executed. Recall that the while loop tests the condtion before the loop is executed. The do while loop The basic form of the do while loop is shown below:
An example of the use of the do while loop is shown in the following program:
The above program checks the current game time (the game hour). If the game time is 12 (midnight) then the while-loop initiates and keeps checking the game time. As long as the game time is equal to 12, the message "Boooo!" keeps appearing. Once the game time hour is no longer equal to 12, the while-loop stops. Because the while loop always executes once (the first time) one "Boooo!" is always displayed. The table below identifies the major parts of the do while loop from the program above.
Where do we go from here? The next section introduces nested loops.
|
|