While Loop
From Sputnik Wiki
(Difference between revisions)
(→Remarks) |
|||
Line 1: | Line 1: | ||
− | = While | + | = While = |
=== Description === | === Description === | ||
Line 6: | Line 6: | ||
<pre> | <pre> | ||
− | While <expression> | + | While ( <expression> ) |
+ | { | ||
statements | statements | ||
... | ... | ||
− | + | } | |
</pre> | </pre> | ||
Line 16: | Line 17: | ||
==== expression ==== | ==== expression ==== | ||
− | If the expression is true the following statements | + | If the expression is true the following statements are executed. This loop continues until the expression is false. |
=== Remarks === | === Remarks === | ||
Line 31: | Line 32: | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | While $i < 20 | + | While ( $i < 20 ) |
− | println( "Value is: " . $i ) | + | { |
− | $i++ | + | println( "Value is: " . $i ); |
− | + | $i++; | |
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Revision as of 16:51, 18 November 2011
Contents |
While
Description
Loop based on an expression.
While ( <expression> ) { statements ... }
Parameters
expression
If the expression is true the following statements are executed. This loop continues until the expression is false.
Remarks
While statements may be nested.
The expression is tested before the loop is executed so the loop will be executed zero or more times.
To create an infinite loop, you can use a non-zero number as the expression such as "While (True)"
The expression can contain the boolean operators of &&, ||, ! as well as the logical operators <, <=, >, >=, ==, !=, <>, eq, eqi, neq and neqi as needed grouped with parentheses as needed.
Example
While ( $i < 20 ) { println( "Value is: " . $i ); $i++; }