Statements are functions, which cannot be used within expressions. Most of them control the flow of the script.
quit
Terminates a running script. The optional parameter sets the exit-code (default: 0), which has no special meaning yet when used in Hamster.
quit
error
Terminates a running script with the given error-message (default: "User defined error!").
error( "File ", $Filename, " not found!" )
assert( <assertion>,
<errmsg> )
assert( <assertion> )
Terminates a running script with the given error-message (default: "Assertion failed!"), if <assertion> returns a value of 0 (FALSE).
assert( FileExists($Filename), "File ", $Filename, " not found!" )
return
Leaves a "sub" and sets its return-value (default: 0). If used outside of a "sub", the script is terminated.
return( 42 )
return( uppercase("fortytwo") )
Same as "return" without parameter, i.e. it leaves a "sub" with a return-value of 0.
endsub
Marks a position in the script with the given identifier. It is used as the target for "goto" and "gosub".
label( never_call_me_with_a_goto_please )
Looks for a "label" with the given identifier and continues execution right after it.
goto( GOTOs_are_REALLY_ugly )
If <condition> gives a value other than 0 (=TRUE), the lines between "if" and "else" are executed, and if it returns 0 (=FALSE), the lines between "else" (if any) and "endif" are executed.
if( $answer = 42 )
print( "The answer is correct!" )
elseif( ($answer = 41) || ($answer = 43) )
print( "The answer is not correct, but acceptable ..." )
else
print( "The answer is wrong!" )
if( $whoanswered = "Deep Thought" )
print( "Reinstall Windows!" )
endif
endif
Marks the beginning of a loop. If "while" is used, the loop is only started, if <condition> returns a value other than 0 (read as: while condition is true).
# see examples under loop/endwhile/until and break/continue
Marks the end of a loop. If "until" is used, the loop is only stopped, if <condition> returns a value other than 0 (read as: until condition is true).
do # ... loop while( $i<10 ) # ... endwhile repeat # ... until( $i>10 ) while( $i<10 ) # ... until( $k=42 )
for( <loop-var>, <limit1>,
<limit2>, <step> )
for( <loop-var>, <limit1>, <limit2> )
Marks the beginning of a "for"-loop.
When the loop is started, the variable <loop-var> is initialized with <limit1>.
The code between "for" and "endfor" is then executed while the value of <loop-var> is lower or equal to <limit2>, or - if <step> is negative - while the value of <loop-var> is greater or equal to <limit2>.
After each loop-run, the value <step> (default: 1) is added to <loop-var>.
var( $i, $k )
for( $i, 1, 10 )
for( $k, 10, 1, -1 )
print( $i, " ", $k )
endfor
endfor
Marks the end of a "for"-loop.
# see example at for
break
Exits a loop. If a <condition> is given, the loop is only exited, if the <condition> returns a value other than zero (read as: break if condition is true).
do break( RasIsConnected ) # do other things loop
continue
Continues with next loop-run. If a <condition> is given, the loop is only continued, if the <condition> returns a value other than zero (read as: continue if condition is true).
$i = 0 repeat continue( $i = 42 ) inc( $i ) until( $i > 100 )