Short Circuit Evaluation

In this chapter we are going to learn about the Short Circuit Evaluation

Introduction

We can create this program quickly using the Quick Start component

ib_quickstart_shortcircuitevaluation.png

Program Steps

After selecting the (Short Circuit Evaluation) template, we will get the next steps in the Goal Designer

gd_quickstart_shortcircuitevaluation.png

The Steps Tree:

x = 0
y = 10
Print Test 1 (New Line)
If (x = 0 AND nice()) AND (y = 10 AND nice())
        Print Great (New Line)
End of IF Statement
Print Test 2 (New Line)
If (x = 1 AND nice()) AND (y = 10 AND nice())
        Print Great (New Line)
End of IF Statement
Print Test 3 (New Line)
If (x = 0 AND nice()) OR (y = 10 AND nice())
        Print Great (New Line)
End of IF Statement
function nice
        Print Nice (New Line)
        Return 1
End of Function

Creating the Program

To create this program we will use the next components

  • Assignment

  • Print Text

  • If Statement

  • Define Function

  • Return

In the begining the Steps Tree is empty

1.png

Set x = 0 using the Assignment component

2.png 3.png 4.png

Set y = 10 using the Assignment component

5.png 6.png 7.png

Print (Test 1)

8.png 9.png 10.png

Test the condition: (x = 0 AND nice()) AND (y = 10 AND nice())

11.png 12.png 13.png

Print (Great)

14.png 15.png 16.png

Print (Test 2)

17.png 18.png 19.png

Check the condition: (x = 1 AND nice()) AND (y = 10 AND nice())

20.png 21.png 22.png

Print (Great)

23.png 24.png 25.png

Print (Test 3)

26.png 27.png 28.png

Check the condition: (x = 0 AND nice()) OR (y = 10 AND nice())

29.png 30.png 31.png

Print (Great)

32.png 33.png 34.png

Define the (Nice) function

35.png 36.png 37.png

Print (Nice)

38.png 39.png 40.png

Return (True) from the (Nice) function

41.png 42.png

Now we have the final Steps Tree in our program

43.png