Back to index

While...End while statement
Executes a series of statements as long as a given condition is 1 (True)

Format:

  While condition
    [ statements ]
  End While

Syntax:

Remarks:

1. If condition is True, all of the statements are executed until the End While statement is encountered. Control then returns to the While statement and condition is again checked. If condition is still True, the process is repeated. If it is False, execution resumes with the statement following the End While statement.

2. You can nest While loops by placing one loop within another.

3. You can use 'Exit While' command that immediately exits the While loop in which it appears. Execution continues with the statement following the End While statement. Exit While can be used only inside a While loop. When used within nested While loops, Exit While transfers control to the loop that is one nested level above the loop where Exit While occurs.

See also:

- Exit statement

Example:

  Counter = 1

  While Counter < 20
     Counter = Counter + 1
     Print Counter

     Input "Again? (y/n): ", again

     If again <> "y" then
       Exit while
     end if
  End While 

  Print "done!"

  Input


Copyright (c) 2000-2006 by Smartphoneware. All rights reserved.