Difference between revisions of "Goto"

From Wiki
Jump to: navigation, search
(added 'switch' snippet)
m
Line 1: Line 1:
 
{{command header|Flow Control}}
 
{{command header|Flow Control}}
  
{{body|goto {label}|The ''goto'' command moves the execution to another part of the script. The destination point is given by a label.}}
+
{{body|goto {label}|The ''goto'' command moves the execution to another part of the script. The destination point is given by a [[label]].}}
  
  

Revision as of 11:06, 3 August 2007


Synopsis

goto {label}

Description

The goto command moves the execution to another part of the script. The destination point is given by a label.


Note:
  • Don't goto out of a sub. Always use return! EasyUO will probably not crash but it is VERY bad programming style.
  • A label in the code must be followed by a colon, where as gotoing to the label does not require a following colon.
  • Inline comments do not work with labels in EasyUO 1.4.


Example

loop:
if %donotloop
	goto exit
goto loop

exit:

Simulating a Switch Statement

Switch structures (like seen in C/C++) can be simulated in EasyUO using the goto statement:

set %a #random % 3 + 1
goto case , %a

case1:
  display ok One
  goto case_exit

case2:
  display ok Two
  goto case_exit

case3:
  display ok Three
  goto case_exit

case_exit:
halt

See also

Main Page Documentation