Program contains 2 nested loops which contain 4 if conditionals. How many paths?
In Roger Pressman's book, there is an example described of a program with 2 nested loops, the in开发者_如何学JAVAner 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.
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
精彩评论