The While Loop

From Catglobe Wiki
Jump to: navigation, search



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.