Skip to content

FOR Loop Functionality

A FOR loop in HuLoop is a powerful structure for automating repetitive tasks a specific number of times. The For Statement command initializes the loop, and it is mandatory to use the Endfor Statement command to mark its end. Commands like Continue Statement and Break Statement enhance loop control by enabling flexibility in execution.

For Statement

The FOR statement allows automation to repeat a set of actions for a specific number of iterations. It is useful for processing lists, looping through elements, and handling repetitive tasks efficiently. The FOR loop must always be closed with an ENDFOR statement to ensure proper execution.

Example: Processing a List of Orders

Suppose you have a list of five orders that need to be processed sequentially. The automation should:

  1. Start at Order 1 and process each order one by one.
  2. Continue the loop until all five orders have been processed.
  3. Exit the loop once the last order is completed.

To achieve this, we will define a FOR loop that runs five times (once for each order).

Steps to configure:

  1. Add a step to the Case.
  2. Select For Statement from the Action drop-down.
  3. Leave Screen Name and Element Key field blank.
  4. In the Parameter section, set:
    startindex=0,endindex=4,incrementby=1
  5. Click Save.
scrn-for-loop-processing-list-of-orders-tabular-view
Tabular View
scrn-for-loop-processing-list-of-orders-card-view
Card View

Expected Outcome on Execution: Initializes the loop and iterates through the range specified in the parameters. For example, if startindex=0, endindex=4, incrementby=1, the loop will execute five iterations (for indices 0, 1, 2, 3, and 4).

ENDFOR Statement

The End For Statement (ENDFOR) marks the completion of the loop block, ensuring that all iterations execute before the automation moves forward.

Steps to configure:

  1. After defining the FOR loop, add a new step.
  2. Select Endfor Statement from the Action dropdown.
  3. Click Save.
scrn-endfor-statement-tabular-view
Tabular View
scrn-endfor-statement-card-view
Card View

Expected Outcome on Execution: Marks the end of the loop block, ensuring all iterations are completed unless interrupted by a Break Statement command.

Refer to the screenshot below to see how a FOR loop is visually structured in the workflow:

scrn-for-loop-visually-structured-in-workflow

Continue Statement

The CONTINUE statement is used inside a FOR loop to skip the current iteration and move to the next one without executing the remaining steps in the loop body. This is useful when certain conditions are met, and you want to bypass specific actions for that iteration while continuing the loop execution.

Example Scenario: Skipping Specific Iterations

Suppose you have a loop that iterates through index values and enters a value in a form field. However, you want to skip the iteration where the index equals 5 and proceed with the next iteration without entering the value.

Steps to configure:

  1. Add a step inside the FOR block.
  2. Specify a condition to check if the index is equal to 5 (e.g., If index is equal to 5).
  3. Select Continue Statement from the Action drop-down.
  4. Leave other fields blank.
  5. Click Save.
scrn-continue-statement-tabular-view
Tabular View
scrn-continue-statement-card-view
Card View

Expected Outcome on Execution:

  • The automation loops through the given range.
  • If index = 5, the automation skips the remaining steps in that iteration and proceeds with the next loop cycle.
  • If the condition is not met, the loop continues executing the remaining steps as usual.

Refer to the screenshot below to see how a Continue Statement is visually structured in the workflow:

In the upcoming sections, we will configure the BREAK statement to exit the loop early under specific conditions.

Break Statement

The Break statement is used within a loop to immediately stop/terminate the for loop execution when a specified condition is met. This prevents unnecessary iterations and optimizes the automation process.

Example Scenario: Exiting the Loop Based on a Condition

Suppose you have a loop that iterates through index values and enters a value in a form field. However, you want to terminate the loop entirely when the index reaches 5, preventing any further iterations.

For example, if the loop starts from 0 and runs until 10, it will stop execution as soon as the index equals 5, even if there are more iterations left.

Steps to configure:

  1. Add a step inside the FOR block.
  2. Specify a condition to check if the index is equal to 5 (e.g., If index is equal to 5).
  3. Select Break Statement from the Action drop-down.
  4. Leave other fields blank.
  5. Click Save.
scrn-break-statement-tabular-view
Tabular View
scrn-break-statement-card-view
Card View

Expected Outcome on Execution:

  • Exits the loop prematurely, halting all further iterations.
  • For example, when index = 5, the Break statement is triggered, stopping the loop.
  • No further records are processed beyond this point.

Refer to the screenshot below to see how a BREAK statement is structured in the workflow:

scrn-break-statement-visually-structured-in-workflow

Back To Top