Using Functions

In this chapter we are going to learn about the Using Functions

Introduction

We can create this program quickly using the Quick Start component

ib_quickstart_usingfunctions.png

Program Steps

After selecting the (Using Functions) template, we will get the next steps in the Goal Designer

gd_quickstart_usingfunctions.png

The Steps Tree:

first()
second()

sum(3,5)
sum(1000,2000)

Print fact(5) (New Line)

If novalue() = NULL
        Print the NoValue() function doesn't return a value (New Line)
End of IF Statement

function first
        Print message from the first function (New Line)
End of Function

function second
        Print message from the second function (New Line)
End of Function

function sum x,y
        Print x+y (New Line)
End of Function

function fact x
        If x = 0
                Return 1
        Else
                Return x*fact(x-1)
        End of IF Statement
End of Function

function novalue
End of Function

Creating the Program

To create this program we will use the next components

  • Call Function

  • If Statement

  • Else

  • Define Function

  • Print Text

  • Return

In the begining the Steps Tree is empty

1.png

Call the first() function

2.png 3.png 4.png

Call the Second() function

5.png 6.png 7.png

Call the Sum() function - Send 3,5 as parameters

8.png 9.png 10.png

Call the Sum() function - Send 1000,2000 as parameters

11.png 12.png 13.png

Call the Fact() function - Send 5 as parameter

14.png 15.png 16.png

Check the output of the NoValue() function

17.png 18.png 19.png

Print a message using the (Print Text) component

20.png 21.png 22.png

Define the First() function

23.png 24.png 25.png

Print a message from the First() function

26.png 27.png 28.png

Define the Second() function

29.png 30.png 31.png

Print a message from the Second() function

32.png 33.png 34.png

Define the Sum() function

This function takes x,y as parameters

The function will print the sum of x and y

35.png 36.png 37.png 38.png 39.png 40.png

Define the Fact() function

41.png 42.png 43.png 44.png 45.png 46.png 47.png 48.png 49.png 50.png 51.png 52.png 53.png 54.png 55.png

Define the NoValue() function

56.png 57.png

Now we have the final Steps Tree in our program

58.png