开发者

Program contains 2 nested loops which contain 4 if conditionals. How many paths?

开发者 https://www.devze.com 2022-12-30 02:34 出处:网络
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 st

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号