Difference between revisions of "Break"

From Scriptwiki
Jump to: navigation, search
 
Line 1: Line 1:
#Redirect [[While_loops]]
+
Breaks out of a while loop.
 +
/break
 +
==Example==
 +
[[var]] %i = 1
 +
[[while]] (1) {
 +
  [[inc]] %i
 +
  [[if]] (%i == 12) { break }
 +
}
 +
[[echo]] Break at %i
 +
The above script would break out of the while loop when %i reached 12. If the script did not have a break command, it would turn into an infinite loop as the statement ''1'' will always be true.
 +
==See Also==
 +
* [[Continue|/continue]]

Revision as of 00:34, 7 April 2008

Breaks out of a while loop.

/break

Example

var %i = 1
while (1) {
  inc %i
  if (%i == 12) { break }
}
echo Break at %i

The above script would break out of the while loop when %i reached 12. If the script did not have a break command, it would turn into an infinite loop as the statement 1 will always be true.

See Also