Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo Pascal - <b> while loop until condition pp 61</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 WHILE                       Loop Until Condition                     pp 61


 Define:  Loop until Boolean condition matches control statement.

 Purpose: Allow looping for an indeterminate amount of repetitions.

 Notes:   The expression controlling the repetition must be of type Boolean.
          The statement is repeatedly executed as long as Expression
          is True.  If Expression is False at loop entry, the loop is not
          executed at all.

          Testing is done at the top of the loop.


 ----------------------------------------------------------------------------


 Usage:
       VAR
          Final       : Integer            ; { Ending value of loop Control }
          Control     : Integer            ; { Declare a control variable   }

       BEGIN
          Final       := 10                ; { Finish with 10               }
          Control     :=  1                ; { Start at 1                   }
          While Control < Final Do           { Boolean test of Control      }
            Begin
            Control   := Control + 1       ; { Control is loop indexer      }
            WriteLn (Control)              ; { Control = Final at exit      }
            End                            ; { End of compound statements   }

          Control     :=  1                ; { Start at 1 again             }

          While Control <= Final Do
            Begin
            Control   := Control + 1       ;
            WriteLn (Control)              ; { Control = Final + 1 at exit  }
            End                            ;
       END.

See Also: For/To Repeat

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson