[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
while                    Signals the Start of a WHILE Loop

 while <bool exp> do
   <statement>;

    The WHILE loop tests to see if <bool exp> is TRUE; if it is,
    <statement> is executed and the test is repeated. This continues until
    <bool exp> is FALSE. If more than one statement is desired, then use a
    compound statement, as shown below:

         while <bool exp> do begin
           <statement>;
           ...;
           <statement>
         end;

    The WHILE loop differs from the REPEAT loop in that the statement(s)
    in a REPEAT loop are always executed at least once; however, if <bool
    exp> is FALSE when the WHILE loop is first encountered, then
    <statement> is never executed.

         <bool exp>   A Boolean expression, yielding TRUE or FALSE.

        <statement>   Any legal statement.

  -------------------------------- Example ---------------------------------

           I := 0;
           while I <= 10 do begin
             J := I*I;
             Writeln(I:2,J:4);
             I := I + 1
           end;

           Number := 1 + Random(1000);
           Tries := 0; Guess := 0;
           while (Guess <> Number) and (Tries < 10) do begin
             Write('Enter guess:  ');
             Readln(Guess);
             Tries := Tries + 1;
             if Guess < Number
               then Writeln('Too low')
             else if Guess > Number
               then Writeln('Too high')
           end;

See Also: do for repeat
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson