User Tools

Site Tools


while

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

while [2006/08/29 16:08] (current)
Line 1: Line 1:
 +======Synopsis:​======
 +__while__ (<​condition>​) <​action>​ \\
 +__while__ (<​condition>​) [{ <​action>​ }]
 +
 +======Description:​======
 +The __WHILE__ loop is a sort of hybrid between the [[FOR]] loop and the [[IF]]
 +control statement. ​ It allows for repetitive action, as with [[FOR]],
 +but the loop iterates (performs the action) only if a specific
 +condition is met, as with [[IF]].
 +
 +The "​condition"​ portion may contain any comparison or assignment
 +allowed in an [[IF]] statement.
 +
 +======Examples:​======
 +To display a warning message 3 times:
 +      @ xx = 3
 +      while ( xx > 0 ) {
 +         echo WARNING! ​ This ship will self destruct in $xx seconds!
 +         @ xx--
 +      }
 +
 +A infinite loop that behaves like the Unix '​yes'​ command:
 +      while ( 1 ) echo yes
 +
 +======Aliases:​======
 +[[UNTIL]] is the exact opposite of __WHILE__. ​ It is essentially the same
 +applying the negation operator (!) to the entire __WHILE__ condition.
 +
 +======Other Notes:​======
 +__WHILE__ has all of the capabilities of [[FOR]], only in a different syntax.
 +The distinction between the two is not great enough to warrant a
 +recommendation of one over the other. ​ If anything, [[FOR]] tends to be
 +more concise than __WHILE__; however, this is not always the case.
 +
  
while.txt ยท Last modified: 2006/08/29 16:08 (external edit)