If and For Statements
If Statement
The If statement is used to execute a function based on a condition. The syntax is as follows:
If (#::myLocalVar = 1): PrintMsg()<>
Condition
- The condition must be a comparison between a local variable and a literal value (or a global variable).
- The comparison is handled by the compiler, not by the SeriaLang interpreter.
- The condition can only be
=(equal),<(less than),>(greater than),<=(less than or equal to),>=(greater than or equal to). - Adding ! before the comparison operator will negate the condition (e.g.,
!=,!<,!>,!<=,!>=). - The local variable must be of type
Int. - The literal value must be of type
IntAND can be a global variable. - You can compare a local variable to another local variable
- You can compare a local variable to a global variable
- You can compare a global variable to another global variable (the result will be hardcoded)
- You can compare a global variable to a literal value (the result will be hardcoded)
Function Call
- You can pass parameters to the function being called.
For Statement
The For statement is used to execute a function multiple times based on a condition. The syntax is as follows:
For (0; 10; 1) -> i: MyFun()<>
About this example:
- The loop will start at
0and end at10, incrementing by1each time. - The loop variable is
i, which will take the values from0to9. - The function
MyFunwill be called10times, withitaking the values from0to9. - You can pass
ias a parameter to the function being called. - You can pass the loop variable as a parameter to the function being called.
Start, End, Step
- The
start,end, andstepvalues must be literal values of typeInt. - The
startvalue is inclusive, meaning the loop will start at this value. - The
endvalue is exclusive, meaning the loop will end before this value. - The
stepvalue is the amount by which the loop variable will be incremented/decremented each time.
Function Call
Same as the If statement.
Additional Notes
The for loop is managed by the compiler, not by the SeriaLang interpreter. This means that the loop will be unrolled at compile time, and the resulting code will be a series of function calls.