Difference between revisions of "Goto"
From Wiki
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{command header|Flow Control}} | {{command header|Flow Control}} | ||
− | {{body|goto {label | + | {{body|goto {label}|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 <b>not</b> require a following colon. | ||
+ | *Inline comments do not work with labels in EasyUO 1.4.}} | ||
− | |||
− | |||
− | |||
− | |||
==== Example ==== | ==== Example ==== | ||
Line 21: | Line 20: | ||
</pre> | </pre> | ||
− | {{ | + | ==== Simulating a Switch Statement ==== |
+ | |||
+ | Switch structures (like seen in C/C++) can be simulated in EasyUO using the goto statement: | ||
+ | |||
+ | <pre> | ||
+ | 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</pre> | ||
+ | |||
+ | == Related Commands == | ||
+ | {| style="background:gainsboro; color:black; border: 2px #aaa solid;" | ||
+ | | Width=250px align=center | [[label]] | ||
+ | |} | ||
+ | =See Also= | ||
+ | {{Flow Control}} |
Latest revision as of 16:58, 5 September 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: |
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
Related Commands
label |
See Also
Flow Control
- Flow control commands allow scripts to make decisions based on the evaluation of boolean expressions.
break | Jumps to first statement outside of loop |
call | Transfers execution to another script file |
continue | Jumps execution of a loop to next iteration |
exit | Exits a called script |
for | Creates a counting loop |
gosub | Transfers execution to the matching sub |
goto | Jumps to another part of the script given by a label |
halt | Stops the script |
if | Executes code based on the evaluation of an expression |
pause | Temporarily stops the execution of the current script |
repeat..until | Creates a loop that checks condition after execution |
return | Returns from a sub |
stop | Ends the script |
while | Creates a loop that checks condition before execution |