06c_WhileAndDoWhile.php

Basic 'While' Loop

The 'for' loop has the 3 statements:

(basic value; comparison over a range; increment to shut it off with);

that is,

for (value; comparison; increment);

   {

   action to be taken;

   }

The 'While' Loop's only got one statement to be evaluated, before the action happens:

while (evaluated)

   {

   action will loop;

   }

All right then,

Stu Stu's equal to 1.
Stu Stu's equal to 2.
Stu Stu's equal to 3.
Stu Stu's equal to 4.
Stu Stu's equal to 5.
Stu Stu's equal to 6.
Stu Stu's equal to 7.
Stu Stu's equal to 8.
Stu Stu's equal to 9.
Stu Stu's equal to 10.

The 'While' Loop again

Ready Steady equals 1.
Ready Steady equals 2.
Ready Steady equals 3.
Ready Steady equals 4.
Ready Steady equals 5.
Ready Steady equals 6.
Ready Steady equals 7.
Ready Steady equals 8.
Ready Steady equals 9.
Ready Steady equals 10.
Ready Steady equals 11.

The 'Dowhile' Loop

how 'do while' loop is different becomes apparent when you ask it to count out even if it's a wrong statement; it will always play out the first iteration regardless. Here, we ask Ready Steady to count out when Ready's 10 or less, and we start by saying Ready's 11. We still get just that first iteration.

Ready Steady equals 11.