The WHILE-LOOP associates a condition with a loop. First, the condition is checked and then the loop is started.
The loop continues until the condition remains TRUE. If the condition becomes FALSE, the loop is completed.
The number of iterations is not known as it is based only on a condition. The loop may not be executed at all,
as the condition is checked at the start of the loop itself.
Following is the syntax of the WHILE-LOOP:
WHILE Condition LOOP
Statement.....
END LOOP;
The FOR-LOOP also associates a condition with a loop but the number of iterations is defined before the execution.
Following is the syntax of the FOR-LOOP:
For counter in start_value .. end_value Loop Statement ...
END LOOP;
Therefore, WHILE-LOOP should be used when a condition has to be checked initially and FOR-LOOP should be used when the number of iterations is known.
The loop continues until the condition remains TRUE. If the condition becomes FALSE, the loop is completed.
The number of iterations is not known as it is based only on a condition. The loop may not be executed at all,
as the condition is checked at the start of the loop itself.
Following is the syntax of the WHILE-LOOP:
WHILE Condition LOOP
Statement.....
END LOOP;
The FOR-LOOP also associates a condition with a loop but the number of iterations is defined before the execution.
Following is the syntax of the FOR-LOOP:
For counter in start_value .. end_value Loop Statement ...
END LOOP;
Therefore, WHILE-LOOP should be used when a condition has to be checked initially and FOR-LOOP should be used when the number of iterations is known.