Meet Virtel Maple 3.4.x! New UI, Custom colors, PQCrypto and Fixes.

Download

Running

Controlling Execution Flow

Objective: Control code execution with conditionals and loops.

Steps:
  • 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.

Steps:
  • 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

run one

Runs a file once in the current flow.

run one (file)
  • file: The path to the file to run (type: VAR).
run one "/init.steps";

This example runs the code in "/init.steps" once.

run if

Runs a file if a boolean value is "true".

run if (boolValue) (file)
  • boolValue: The boolean value to check ("true" or "false") (type: VAR).
  • file: The path to the file to run (type: VAR).
var set "true" condition; run if condition "/action.steps";

This example runs "/action.steps" because "condition" is "true".

run while

Runs a file in a loop while a boolean value is "true".

run while (boolValue) (file)
  • boolValue: The boolean value to check (type: VAR).
  • file: The path to the file to run (type: VAR).
var set "true" isRunning; run while isRunning "/loop.steps";

This example runs "/loop.steps" repeatedly until "isRunning" becomes "false".

run each

Runs a file for each element in a list, storing the current element in a variable.

run each (valueList) (itemVarName) (file)
  • 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).
lst new items; lst set items "0" "apple"; lst set items "1" "banana"; run each items item "/processItem.steps";

This example runs "/processItem.steps" for "apple" and "banana".

run for

Runs a file for each index in a range from first to last, storing the index in a variable.

run for (first) (last) (indexVarName) (file)
  • 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).
run for "0" "2" i "/printIndex.steps";

This example runs "/printIndex.steps" for i = 0, 1, and 2.

run flow

Starts a new flow from a file and stores its name in a new variable.

run flow (file) (varNewFlowName)
  • 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).
run flow "/background.steps" flowName; csl write flowName;

This example starts a new flow with "/background.steps" and prints its name (e.g., "flow-1").

run pause

Pauses the execution of the flow for a specified time in milliseconds.

run pause (time)
  • time: The pause duration in milliseconds (type: VAR).
csl write "Starting"; run pause "1000"; csl write "Done";

This example prints "Starting", waits 1 second, and then prints "Done".

run break

Breaks the current loop (while, each, for) if the flow is not in "inlife" mode.

run break
    var set "true" isRunning; run while isRunning "/loop.steps"; run break;

    This example breaks out of a while loop immediately.

    run stop

    Stops the current flow if it is not in "inlife" mode.

    run stop
      csl write "Running"; run stop; csl write "This won’t print";

      This example stops the flow after printing "Running".