Running
Controlling Execution Flow
Objective: Control code execution with conditionals and loops.
- Run a file conditionally:
var set "true" condition; run if condition "/action.steps";
- "condition" is the boolean variable.
- "/action.steps" is the file to run if the condition is true.
- Run a file in a loop:
var set "true" isRunning; run while isRunning "/loop.steps";
- "isRunning" is the loop condition.
- "/loop.steps" is the file to run repeatedly.
- Stop the flow:
run stop;
Practical Example
Objective: Run a file for each item in a list.
- Create and populate a list:
lst new items; lst set items "0" "apple"; lst set items "1" "banana";
- Run a file for each item:
run each items item "/processItem.steps";
Tips
- Use
run pause
to introduce delays in execution. - Be cautious with loops to avoid infinite execution.
- Use
run break
to exit loops when needed.
Conclusion
Execution control commands like run if
, run while
, and run each
provide powerful ways to manage flow execution in your Virtel Steps programs.
Commands
Runs a file once in the current flow.
file
: The path to the file to run (type: VAR).
This example runs the code in "/init.steps" once.
Runs a file if a boolean value is "true".
boolValue
: The boolean value to check ("true" or "false") (type: VAR).file
: The path to the file to run (type: VAR).
This example runs "/action.steps" because "condition" is "true".
Runs a file in a loop while a boolean value is "true".
boolValue
: The boolean value to check (type: VAR).file
: The path to the file to run (type: VAR).
This example runs "/loop.steps" repeatedly until "isRunning" becomes "false".
Runs a file for each element in a list, storing the current element in a variable.
valueList
: The list to iterate over (type: LIST).itemVarName
: The name of the variable for the current element (type: VAR).file
: The path to the file to run (type: VAR).
This example runs "/processItem.steps" for "apple" and "banana".
Runs a file for each index in a range from first to last, storing the index in a variable.
first
: The starting index (type: VAR).last
: The ending index (type: VAR).indexVarName
: The name of the variable for the current index (type: VAR).file
: The path to the file to run (type: VAR).
This example runs "/printIndex.steps" for i = 0, 1, and 2.
Starts a new flow from a file and stores its name in a new variable.
file
: The path to the file to run in a new flow (type: VAR).varNewFlowName
: The name of the variable to store the flow name (type: VAR).
This example starts a new flow with "/background.steps" and prints its name (e.g., "flow-1").
Pauses the execution of the flow for a specified time in milliseconds.
time
: The pause duration in milliseconds (type: VAR).
This example prints "Starting", waits 1 second, and then prints "Done".
Breaks the current loop (while, each, for) if the flow is not in "inlife" mode.
This example breaks out of a while loop immediately.
Stops the current flow if it is not in "inlife" mode.
This example stops the flow after printing "Running".