Control Structures

From Wiki
Revision as of 12:15, 3 August 2007 by MoonRaver (Talk | contribs)

Jump to: navigation, search

Goto's

Goto's are an archaic and powerful command to automatically move to a different point in a program. They never return unless another goto is used. They should never be used to return from a subroutine.

label

A label is a marker for the point a goto command will jump to. These are created by using any word that isn't a command, and suffixing it with a colon, like this...

mylabel:

goto

A goto is used to jump directly to a label as defined above. This is accomplished by using goto {label}

goto mylabel

Subs

The term sub is short for subroutine. Subs are an important feature of the EasyUO script that will make your scripts more logically structured, easier to read, and will make you have to write less code.

A basic sub definition starts with a sub statement followed by the subs name (sub names are case insensitive), a number of script lines and ends with a return statement.

sub testSub
  ...
  return

If parameters were added to the calling gosub command they will be present in the variables %1, %2, and so on. The variable %0 holds the number of parameters passed. As all variables are in the global scope, the %0, %1, %2.. will be overwritten if you call another sub from inside a sub.


Note:
  • Do not GOTO out of a sub, always use return! EasyUO will probably not crash but it is very bad programming style.
  • Inline comments do not work with the sub command in EasyUO 1.4; this has been fixed in EasyUO 1.5 however.


gosub

The gosub command transfers the execution to a sub with the name given by the parameter.

gosub sub_name

Parameters can be added after the sub name. They will be transfered in the variables %1, %2, and so on. The variable %0 holds the number of parameters passed.

return

The return command transfers the execution back to where the sub was called using gosub.

return