Skip to main content

If/Else Logic

Using If/Else

Cycle has the ability to use If / Else / ElsIf structures. The basic syntax of an If statement is shown in the following diagram. The only required elements of the If Structure is the If and EndIf. The use of Else and ElsIf elements are optional.

If/Else logic

The figure below demonstrates a Feature File that prompts the user for a number and If/Elsif/Else to determine if the number entered was 1, 2, 3 or none of those.

Sample If/Else flow

Combining If/Else with "I execute Scenario..."

In some cases it may be helpful to call an imported Scenario inside of an If statement, as in the example below which would wait .5 seconds in the middle of each loop:

Sample If/Else flow

The benefit of using the If/Else here is that the overall Feature can keep running even in the event of a failure of the inner Looping Scenario.

Note: Though a failure in an inner Scenario that is called from an If/Else would cause an error to display in the output panel, the top level feature would still report a success.