| | Basic, C and Jave Syntax: When a While Loop Construct is encountered during the program's execution, it evaluates the condition specified in the <condition> element. If the condition is met, the statements within the <statements> element are executed until the end of the While Loop Construct is encountered, at which point the program flow returns to the begining of the While Loop Construct and repeats the process. If the condition is not met or the optional Loop Termination keywords are encountered, execution resumes with the statement following the end of the While Loop Construct.C & Java Syntax only: If while executing the statements within the <statements> element, a Loop Continuation keyword is encountered, then the program flow skips the remaining statements and resumes just before the ending of the While Loop Construct. |
| | In the following example, a While Loop Construct is shown that executes the statements in <statements> only if the original value of A is less than 100 and then repeats the execution of the statements in <statements> as long as the value of A remains less than 100.
| Visual Basic & BASIC | C & Java |
While A < 100
<statements>
Wend | While (A < 100){
<statements>
} |
In the following example, a While Loop Construct is shown that executes the statements in <statements1> only if the original value of A is equal to 1, but never gets to execute the statements in <statements2> because a Loop Termination keyword was encountered which caused the program flow to jump to the ending of the While Loop Construct.
| Visual Basic & BASIC | C & Java |
While A = 1
<statements1>
Exit While
<statements2>
Wend | While (A == 1){
<statements1>
Break;
<statements2>
} |
In the following example, a While Loop Construct is shown that executes the statements in <statements1> only if the original value of A is Greater than 50, and then repeats the execution of the statements in <statements1> as long as the value of A remains greater than 50, but only executes the statements in <statements2> if the value of B is equal to 1, because a Loop Continuation keyword was encountered which caused the program flow to skip past all the remaining statements in the While Loop Construct.
| Visual Basic & BASIC | C & Java |
Not posible using only the While Loop Construct in Basic syntax. To skip the statements within <statements2>, place them within an If Selection Contruct as shown:While A = 1
<statements1>
If B = 1 Then
<statements2>
End If
Wend | While (A > 50){
<statements1>
If (B != 1) Continue;
<statements2>
} |
In the following example, a While Loop Construct is shown that executes the statments in <statements> 12 times. NOTE: The For Loop Construct is better suited for the conditions in this example.
| Visual Basic & BASIC | C & Java |
A = 1
While A < 12
<statements>
A = A + 1
Wend | A = 1
While (A < 12){
<statements>
A++
} |
|