Control structures

if

The if statement executes a block of commands if a condition is true. You can optionally test alternate conditions with else if and execute a block of code if all other conditions fail with else.

if condition1 [then]
    commands to execute if condition is true
else if condition2
    commands to execute if condition2 is true
else
    commands to execute otherwise
endif

For example:

if ( $F == 1 ) then
    echo Frame One
else
    echo Not Frame One
endif

Currently, statements inside the if clause must occur on separate lines. That is, statements like if ($F == 1) echo Frame One will not work.

for

The for statement loops over a block of statements, incrementing a “counter” variable from a start number to an end number, optionally by a certain step.

for count_variable = start to end [step stepsize]
    commands to loop
end

Do not add a $ before the name of the count variable in the for statement. For example:

for i = 1 to 3
    echo $i
end

for i = 1 to 100 step 3
    echo $i
end

foreach

The foreach statement loops over a block of statements, setting a variable to the next element in a list each time.

foreach iterator_variable (list_string)
    commands to loop
end

For example:

foreach i ( a b c )
    echo $i
end

foreach object ( `run("opls -d")` )
    echo Object $object
end

HScript does not have a real list or array type. The list the for each statement loops over is a string that HScript splits into elements the same way it parses the command line into arguments. See how HScript splits up the command line.

while

The while statement loops over a block of statements as long as a condition is true. while condition commands to loop while condition is true end For example:

set i = 0
while ( $i < 10 )
    set i = `$i+1`
    echo $i
end

break/continue

The break statement exits the current loop prematurely. The continue statement ends the current iteration of a loop prematurely and starts the next one.