Rubiscape provides loop control statements or conditions that you can use to control the execution of your workbook. They are,

1. If Else-End
2. While-End
##### Figure: Conditions in Rubiscape

You can apply the If Else and While conditions as predecessors to the algorithms to decide the execution flow. Refer to Building Algorithm Flow in a Workbook Canvas.

The if-else condition decides execution flow based on whether the specified condition results in True or False.
The while loop helps to execute a particular flow until the condition is true.

In both cases, the condition is checked before execution, and based on the outcome, the respective block of statements is executed.

You can use the loop control statements in scenarios where you want to execute different tasks based on certain conditions.

# Using If Else Condition

To use the If Else condition, follow the steps given below.

1. Open the required workbook or create a new workbook. Refer to Opening a Workbook or Creating a Workbook.
The selected workbook canvas is displayed.
3. Drag-and-drop or double-click the If Else node from Condition into the workbook canvas.
##### Figure: Adding If Else Condition
4. Connect the reader to the If Else node.
5. Drag-and-drop or double-click the algorithm for which you want to test the Task Pane condition into the workbook canvas. Refer to Building Algorithm Flow in a Workbook Canvas.
6. Click the algorithm node and select the Properties displayed on the right-hand side. Refer to Algorithm Properties.
7. Connect the If Else node to the algorithm.
8. Connect the algorithm node to the End node. Note: The algorithms should always be inserted between the Condition and the End node.
9. Click the If Else node and select the Properties displayed on the right-hand side. Refer to If Else Condition Properties.
10. Click the End node and select the Properties displayed on the right-hand side. Refer to End Properties.
11. Click the Save icon ( ) on the function pane of the workbook to save the workbook.
12. Click the Run icon ( ) on the Function Pane of the workbook to run the workbook.
A sample workbook using the If Else condition is shown below.
##### Figure: Sample Workbook Canvas with If Else Condition

The algorithms are executed based on the conditions selected for If Else. If the condition evaluates to True, the algorithms selected in the If Tasks are executed, else the algorithms selected in the Else Tasks are executed.

## If Else Condition Properties

The If Else Condition Properties show Task Name fields, Clause fields associated with it, Else Condition check box, and Else Condition Tasks. ##### Figure: If Else Condition Properties

The table given below describes the functions present on the If Else condition.

###### Table: Description of Properties of If Else

The figure given below is an example of If Else Properties. The selected condition is If Else, and the algorithms connected to the If Else node are Decision Tree and Linear Discriminant Analysis.

##### Figure: If Else Condition Properties Example

In the example above, refer to Figure 9. The variable added is Test1 with the Current Value of 10. The If condition selected for the variable is Test1 == 10. In this example, the value of Test1 is 10, hence the Decision Tree algorithm is executed. If we change the value of the variable Test1 to anything other than 10, then the Linear Discriminant Analysis algorithm would be executed.

## End Condition Properties

You need to end any condition that you have selected. In the End node, you can select the tasks you want to End.

##### Figure: End Condition Properties
 Note: When you drag-and-drop or double-click the If Else or While condition, the End node is also inserted into the workbook canvas along with it.

The table given below describes the functions present on the While condition.

###### Table: Description of Properties of End Node
 Field Name Description Remarks Task Name It is the name of the task (End). — End Tasks It lets you select the End tasks for If Else Node. Connect the algorithms whose execution you want to stop to the End node. Assign Resultant Variable It lets you select the user-defined variables to which you can assign the result of the algorithm that is executed. —

# Using While Condition

To use the While condition, follow the steps given below.

1. Open the required workbook or create a new workbook. Refer to Opening a Workbook or Creating a Workbook.
The selected workbook canvas is displayed.
3. Drag-and-drop or double-click the While node from Condition into the workbook canvas.
##### Figure: Adding While Condition
4. Connect the reader to the While node.
5. Drag-and-drop or double-click the desired algorithm into the workbook canvas. Refer to Building Algorithm Flow in a Workbook Canvas.
6. Connect the While node to the algorithm.
7. Connect the algorithm node to the End node. Note: The algorithms should always be inserted between the Condition and the End node.
8. Click the While node and select the Properties displayed on the right-hand side.  Refer to While Condition Properties.
9. Click the algorithm node and select the Properties displayed on the right-hand side. Refer to Algorithm Properties.
10. Click the End node and select the Properties displayed on the right-hand side. Refer to End Properties.
11. Click the Save icon ( ) on the Function Pane of the workbook to save the workbook.
12. Click the Run icon ( ) on the Function Pane of the workbook To run the workbook.

A sample workbook using the While loop is shown below.

##### Figure: Sample Workbook with While Loop
The algorithm connected to While is executed as long as the While condition is true.

## While Condition Properties

The While Condition Properties show Task Name fields and Clause fields associated with it.

##### Figure: While Condition Properties

The table given below describes the functions present on the While condition.

###### Table: Description of Properties of While Node
 Field Name Description Remarks Task Name It is the name of the condition selected (While). — While Tasks It lets you select the successor algorithms which are executed while the condition evaluates to True. — Clause It lets you create a complex condition. You can add more than one clause. Parameter It lets you select the variable for the condition. Although you can use any type of variable, it is recommended to use only numerical variables in the While condition.Refer to Adding a Variable. Condition It lets you select the mathematical operator for your variable. — Value It lets you enter the required values to test or execute the successor algorithms connected to the While condition. This value is compared with the Current Value of the added variable to evaluate the expression. Notes: Rubiscape currently supports only the value of the variable to be incremented by one. So, make sure that the Condition and the Value selected are equal to or greater than the current value.The value is incremented internally and does not reflect in the current value of the variable.

The figure given below is an example of While Properties. The selected condition is While, and the successor algorithm selected to execute the While condition is Decision Tree.

##### Figure: While Condition Properties Example

In the example above, refer to Figure 13. The newly added variable is Test1 with the Current Value as 10. The While condition is Test1 <12. In this example, the Decision Tree algorithm is executed twice until the current value of Test1 is less than 12. In the third iteration, the current value becomes 12, the while condition fails at this point, and the execution stops.

## End Properties

You need to end any condition that you have selected. In the End node, you can select the tasks you want to End.

##### Figure: End Condition Properties Note: When you drag-and-drop or double-click the If Else or While condition, the End node is also inserted into the workbook canvas along with it.
`Table of Contents`