Difference between revisions of "The While Loop"

From Catglobe Wiki
Jump to: navigation, search
 
Line 1: Line 1:
 
[[Category:Program_Control_Statements]]
 
[[Category:Program_Control_Statements]]

+
{{HelpFiles}}
  
 
===The While Loop===
 
===The While Loop===

Latest revision as of 09:16, 14 December 2011



The While Loop

The general form of the while loop is:

while (condition) statement;

where statement can be a single statement or a block of statements, and condition defines the condition that controls the loop, and it may be any valid boolean expression. The statement is performed while the condition is true. When the condition becomes false, program control passes to the line immediately following the loop.

Here is a simple example for while loop

{

number i = 1;

while (i<6)

{

print(i);

i = i + 1;

}

print("Counting completed.");

}

The output from the script is shown here:

1

2

3

4

5

Counting completed.