在执行循环语句时检查IF和WHILE循环的条件

时间:2018-06-04 00:27:23

标签: pseudocode

考虑以下两个循环:

if condition 1: 
   Statement1;
   Statement2;
   Statement3;

While condition2:
   Statement1;
   Statement2;
   Statement3;

现在用于IF循环;在执行每个语句(statement1,statement2,statement3)之后或仅在执行statement3之后检查condition1?

While循环的相同问题;在执行每个语句(statement1,statement2,statement3)之后还是仅在执行statement3之后检查condition2?

(Statement1,statement2和statement3可以操纵条件)

1 个答案:

答案 0 :(得分:0)

x = 1
while x==1:
    x = 2
    print(x)
    x = 3
    print(x)

if x == 3:
    x = 4
    print(x)
    x = 5
    print(x)

'''
output:
2
3
4
5

No conditions were checked
 before the statements inside the 
 block were finished
'''

如评论中所述,if不是循环,其条件仅在开始时检查一次。每次循环缩进部分

后,都会检查while