# ISTQB Foundation Level Paper 3, no. 37

How many test cases are necessary to cover all the possible sequences of statements (paths) for the following program fragment?

``````if (condition 1)

then statement 1

else statement 2

fi

if statement 2

then statement 3

fi
``````

The answer is supposed to be 3 but I don't know why? can someone draw a diagram or explain this? ISTQB Foundation Level Paper #3 no. 37.

• Could you use brackets to represent any nesting ? – Edward_Haigh Jun 14 '17 at 14:55

It's three paths. If I express it via a more c# syntax you get this:

``````if (condition1)
{
statement = statement1;
}
else
{
statement = statement2;
}
``````

That gives us 2 paths:

``````condition1 == true -> statement1
condition1 == false -> statement2
``````

Next, statement 2 is checked for true/false:

``````if (statement2)
{
statement = statement3
}
``````

So your 3 end points are:

``````condition1 true -> statement1 (value doesn't matter)
condition1 false -> statement2 true -> statement3
condition1 false -> statement2 false -> statement2
``````
• This is why having brackets is essential! Now it makes sense. – Edward_Haigh Jun 15 '17 at 7:40

I think statement coverage is 2. let's take condition1 = a>b condition2 = c>d test case1: a=3,b=1,c=5 and d=3 in this tets case statement 1 and statement 2 are covered testecase2: a-1,b=3,c=5 and d=3 in this case statement 2 and statement 3 are covered i.e. with two test case we can cover all statements so statement coverage is 2