Control Flow
Block statements are used to group several statements into a single block. The block is delimited by a pair of curly brackets {}
. Block statements are commonly used with control flow statements such as if, for or while.
if-else statement
Use the if
statement to execute a statement if a logical condition is true
. Use the optional else
clause to execute a statement if the condition is false
. Lastly, you can have a if-else if
statement which is a block statement that when the if
condition fails, it checks if the next if
conditions is true or not, and then the next one... and so on..
Here is an example:
For statement
A for
loop repeats until a specified condition evaluates to false
. The Hedgehog Script for
loop is the same as JavaScript, which is similar to the Java and C for
loop. A for
statement looks as follows:
for ([initialExpression]; [condition]; [incrementExpression]) {
statement }
Here is an example:
while and do-while statement
The while
statement creates a loop that executes a specified statement as long as the test condition evaluates to true
. The condition is evaluated before executing the statement.
Here is the syntax for while
statement:
while (condition) {
statement }
The do...while
statement creates a loop that executes a specified statement until the test condition evaluates to false
. The condition is evaluated after executing the statement, resulting in the specified statement executing at least once.
Here is the syntax for do...while
statement:
do {
statement }
while (condition);
Here are examples for while
and do...while
statements in Hedgehog Lab:
These are the basic ways to control the logical flow of your script/program in Hedgehog Lab.