Skip to content

How do I skip the execution of code inside the loop for the current iteration and move the control to the beginning of the loop for next iteration

This example demonstrates skipping the execution of code inside the loop for the current iteration and continuing with the next iteration.

In the solution shown below, the input field names in HICC are validated within the "foreach-endForeach" construct using the "verifyVisible" command. Based on the environment, fields that are not applicable are skipped using the "continue" command within the "if-endIf" construct.

Note: You can use store or storeXXX command to define the value (string or boolean) of the variable. The notation to reuse the value of the variable in Worksoft SaaS is ${<Variable Name>}.

Solution:

# Command Target Value
Start the foreach construct. Iterate the block of code for each input field name
1 foreach
field_name Number of people on insurance policy:,Age of the oldest person on insurance policy: 
Start the If construct. If the environment is Production, skip the validation of input field "Number of people on insurance policy:"
2 If
"${<Variable Name>}"=="Production" && "${field_name}"=="Number of people on insurance policy:"

Skipping the current iteration
3 continue 
End of if block
4 endIf


Verify the input field name visibility
5 verifyVisible
//label[text()="${field_name}"]

End of foreach block
6 endForeach

Tips, Tricks, Gotchas & Best Practices:  

  • The value for the variables can also be driven from a Data-file, System Defined Variable or User Defined Variable.
  • In conditions, while comparing numeric values, do not use double quotes("), as it would consider the value as a string.
  • As a best practice, it is always advisable to define the variable names without any spaces and if you want to differentiate the words, use underscore or hyphen.

Feedback and Knowledge Base