Condition if

This command is used to build all conditional statements. The condition field defines a logical condition, that is a condition, which may have either true or false logical value. If the condition is true, statements included after the if keyword will be executed, whereas in another case statements included after the else keyword will be performed. The else keyword is optional and does not have to be included. In this case, if the logical condition is false, no action will be performed. After the else keyword, further nested conditional statements, loops, etc. may be included.

The if conditional statement must be properly terminated with the end keyword end

In case of more complex conditions, where sequence of evaluation is important ( and ) parentheses may be additionally used, e.g.:

(q1=1 & q2=1) | (q1=2 & q2=2)
Syntax Meaning
if condition then Script fragment_1; else Script fragment_2; end

If the condition is true, then the script fragment_1 will be executed. Otherwise, the script fragment_2 will be executed.


Example 1

The condition checks answers for question q55. If an answer with code 1 was selected, the condition will be evaluated as true and the other screen will be shown.

if q55=1 then ask; else skip; end;


Example 2

If in question q5, in subquestions 1 to 10, an answer with code 1 is selected, then in the current questions only answers with codes 1 to 10 that meet the condition will be shown.

if q5s1-10=1 then ask i1-10; else skip i1-10; end;

It should be noted that the condition has been built using a range, which allows shortening of equivalent conditions in the form:

if q5s1=1 then ask i1; else skip i1; end;
if q5s1=2 then ask i2; else skip i2; end;
if q5s1=3 then ask i3; else skip i3; end;
if q5s1=4 then ask i4; else skip i4; end;
if q5s1=5 then ask i5; else skip i5; end;
if q5s1=6 then ask i6; else skip i6; end;
if q5s1=7 then ask i7; else skip i7; end;
if q5s1=8 then ask i8; else skip i8; end;
if q5s1=9 then ask i9; else skip i9; end;
if q5s1=10 then ask i10; else skip i10; end;


Example 3

An example using parentheses The condition checks combination of codes (1,3,4 or 2,7,8) and performs a script statement.

if (q12=1 & q12=3 & q12=4) | (q12=2 & q12=7 & q12=8) then ask; else skip; end;

Conditional statements a are often combined with variables, functions, commands, etc.