You’ve mastered flow control. Let's recap
Congrats! Now you can control the flow of your Script using the information from the page.
Flow control items are complex. We call them parents, as they conditionally pass control to their children when it's time. Some parents will also modify the scope for the children.
Loops
Loop actions, e.g. as "each" and "while", go over a collection of items, passing control several times.
- Use the "each" when there is a known list of elements to go over. The pipeline should return a list of elements. On every iteration of the loop, children's scope narrows down to the current node.
- Use the "while" when you don't know the number of iterations, so the action goes while the condition is
true
. The pipeline should return a boolean value.
Conditions
Conditional actions, such as "if", "elseIf", "else", or "find", invite children to play or skip based on the condition's outcome. The pipeline should return a boolean value.
- The "if" – conditionally passes control to the children. If the value is
true
, the control goes to the children. - The "elseIf" – works similarly; it must go right after an "if" or "elseIf".
- The "else" – must go right after the "if" or "elseIf". Use it to pass the control to an alternative chain of the children actions when the previous item's pipeline returns
false
. - The "find" – looks for a single element on the page to use for the children's scope. By default, the action throws an error when the node is missing. With the
optional
setting, it will silently skip the children.