The What
Description
The for
loop executes code until one of the following is true:
- Expression 2 is
false
break
ends the loopingreturn
ends the looping and exits the function- The computer (or server) runs out of memory.
Parameters
expression1
- (optional) Expression 1 is evaluated at the start of the loop, but only one time. You can have a comma-separated list of expressions here.
expression2
- (optional) Expression 2 is evaluated at the start of each loop iteration. When true, the code within the code block is evaluated; else the loop stops. You can have a comma-separated list of expressions here. When there are multiple expressions separated by a comma, the last one is used to determine if the loop should continue. If this expression is empty, the loop runs indefinitely.
expression3
- (optional) Expression 2 is evaluated at the end of each loop iteration. You can have a comma-separated list of expressions here.
Show It in ActionBasic
There are multiple expressions in the for
loop parameters. Let’s see how each of these works, what the sequencing is, and what happens when any of them are not provided (since they are optional).
Keep It Simple, Stupid (KISS) - the best kiss you'll get in code.
Go DeepPro
Let’s take a deeper look at the for
loop instruction.