Home > FAQ, How To's > How To Create ‘if’ Statements (Conditional Scripting)

How To Create ‘if’ Statements (Conditional Scripting)

Overview

‘if’ Statements are a basic fundamental of programming languages.
It is used for creating condition checks.
conditional statements are features of a programming language which perform different computations or actions depending on whether a programmer-specified Boolean condition evaluates to true or false
This how to will introduce you to ‘if’ sentences and show you how you can use it within survey to go.

How it is constructed?

IF
(predicate)


THEN


(consequent)


ELSE


(alternative)

Within the ‘Predicate’ place you should write the condition.
Within the ‘Consequent’ you should write the code that will be executed if the condition is ‘true’.
Within the alternative you should write the code that will be executed if the condition is ‘false’.

How it really looks like?

if(Answer(2)==5)

{

    SetAnswer(CurrQues,2);

}

else

{

    Prompt(“This is a test”);

}

This example will do the following:
“if the answer of question 2 equals to 5, set the answer of the current question with the value 2.
Else, Prompt a message saying ‘This is a test’ “.

‘if’ sentences in SurveyToGo are useful within Start Scripts, End Scripts and ‘Advanced Scripts’.
They are not need for ‘Entrace Rules’ & ‘Jump Rules’.

Adding more conditions?

‘if’ statements are not limited to only one condition and alternative but many, although, it is not recommended to use more then 10 alternatives in the same ‘if’ statement, as some operating systems such as ‘Android’ have some limitation’s and might not process it right.
Example of several conditions:

if(Answer(1)==2 && Answer(2)==3)

{

    x=15;

}

else if(Answer(1)==3 && Answer(2)==4)

{

    Prompt(“This is a test”);

}

else if(Answer(1)==4 && Answer(2)==5)

{

    Prompt(“This is another test test”);

}

else

{

    Prompt(“Thats it”);

}

This will do the following:
if Answer of 1 is equal to 2 AND answer of 2 is equal to 3 -> input value 15 to x;

Else if : if Answer of 1 is equal to 3 AND answer of 2 is equal to 4 -> Prompt:”This is a test”

Else if : if Answer of 1 is equal to 4 AND answer of 2 is equal to 5 -> Prompt:”This is another test”

Else: -> Prompt:”This is another test”

Using an ‘if’ statement within an ‘if’ statement?

Similar to the movie Inception with the dreams, there can be an ‘if’ statement within an ‘if’ statementJ.

That’s it!

Visit us at: http://www.dooblo.net

Categories: FAQ, How To's
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: