Difference between revisions of "While"

From Wiki
Jump to: navigation, search
(See Also: added references)
Line 1: Line 1:
__NOTOC__
+
{{command header|Flow Control}}
== While ==
+
{{body|while ( expression ) { }|While loops test the expression and if true, continuously executes the code provided until the expresion is no longer true. Unlike [[repeat..until]], while loops will not execute at all if the expression evaluates to false.}}
'''Flow Control'''
+
=== Synopsis ===
+
[[while]] ( expression )
+
{
+
}
+
=== Description ===
+
While loops test the expression and if true, continuously executes the code provided until the expresion is no longer true. Unlike [[repeat..until]], while loops will not execute at all if the expression is false.
+
  
 
==== Example ====
 
==== Example ====
Line 25: Line 18:
 
%Test holds the value of 10. Notice the condition "%Test < 10". If that becomes true, the script wont jump back to while loop start, but continues normally.
 
%Test holds the value of 10. Notice the condition "%Test < 10". If that becomes true, the script wont jump back to while loop start, but continues normally.
  
=== See Also ===
+
{{footer}}
{|
+
| width=200px | [[break]] || width=200px | [[continue]] || width=200px | [[for]] || width=200px | [[repeat..until]]
+
|}
+
----
+
{|
+
| Width=200px | [[Main_Page]] || Width=200px | [[Documentation]] || Width=200px | [[Documentation#Flow_Control|Flow Control]]
+
|}
+

Revision as of 10:27, 27 August 2005

Synopsis

while ( expression ) { }

Description

While loops test the expression and if true, continuously executes the code provided until the expresion is no longer true. Unlike repeat..until, while loops will not execute at all if the expression evaluates to false.

Example

set %Test 1

while %Test < 10
{
;Code between these brackets, gets executed, while %Test is smaller than 10
;When its 10, it wont jump back to first bracket.
set %Test %Test + 1
}
display ok %Test $
halt

%Test holds the value of 10. Notice the condition "%Test < 10". If that becomes true, the script wont jump back to while loop start, but continues normally.

See also

Main Page Documentation