views:

49

answers:

1

In Roger Pressman's book, there is an example described of a program with 2 nested loops, the inner loop enclosing four if statements. The two loops can execute up to 20 times. He states that this makes about 10^14 paths. To get a number this large, it seems the paths inside the loops are multipllied by 2^40, i.e. 2^20 times 2^20 to account for all the possibilities of going through the two loops. I can't see why this factor is not just 400, i.e. 20 times 20. Can someone shed some light? It will help if you have the ppt slides and can see the program graph. Thanks.

A: 

The inner block would be multiplied by 20*20 if the loops execute exactly 20 times each, since the inner block would be run through a fixed 20*20 times, and all that would matter is the path through it each time. You said they execute "up to 20 times", so you need to account for control flow changes if the inner one executes 19 times, 18 times, etc., and then the same for the outer one

Michael Mrozek
I think you've got your finger on it, thanks. There is a diamond (decision) connecting the loops, so taking a loop is not predetermined. I hate when authors of books give vague, incomplete information and continue to do so edition after edition!
Student4Life