Control Structures Components

In this chapter we are going to learn about the Control Structures Components

Introduction

These components could be used to take decisions and separate the execution to different branches where one of these brances will be executed based on the evaluation result of specific conditions

Also it can be used to repeat the execution of specific commands

Control Structures Components

We have many components in this category:

  • If Statement

  • Else

  • Else If

  • Switch

  • Case

  • Else (Other)

  • For Loop

  • For In Loop

  • While Loop

  • Do Again Loop

  • Try Catch

  • Exit Command

  • Loop Command

If Statement

In the Interaction Page we can determine the Condition

If Statement

For example, if the condition is (x=1) the next steps will be generated in the Steps Tree

If Statement

Sure, This is not a complete program, and will lead to runtime error because the x variable is not defined!

Else

Using (Else) We can determine what to do if the (If Statement & Else If Statements) conditions are not True

Else

Example:

Else

Else If

Using many (Else If) statements, we can evaluate different conditions

In the Interaction Page we can determine the condition

Else If

In the next example, We have the X variable and we use (If Statement) and (Else if) statements to determine what to do based on the variable value

Else If

Switch

Using the Switch component we can take decision based on the different values of a variable.

We will create the next example:

x = 10
Switch x
        Case 1
                Print One (New Line)
        Case 10
                Print Ten (New Line)
        Else
                Print Other Number! (New Line)
End of Switch

Start new program

1.png

Define the X variable, and set X to 10

2.png 3.png

This will generate the next step

4.png

Start using the Switch component

5.png 6.png 7.png

Now we can handle the different cases

Case

The next steps check if x = 1

8.png 9.png 10.png

In this case we will print (one)

11.png 12.png 13.png

The next steps check if x = 10

14.png 15.png 16.png

In this case we print (Ten)

17.png 18.png 19.png

Else (Other)

Using the Else (Other) component we can check the other cases

20.png 22.png

In this case we print (Other Number!)

23.png 24.png 25.png