python sentence structure (pass statement and control statements)

python sentence structure (pass statement and control statements)

break- out of the loop: for statements and can jump out of the loop while statement. If you break out of for and while loop, any corresponding loop else chunks are terminated

continue- out of this cycle: Tell python out of the remaining statements in the current loop block, and then continue to the next round of the cycle

Loop else clause can have it in an exhaustive list (with a for loop) or condition becomes FALSE (to while loop) is executed when the loop terminates lead, but the cycle is break, else clause is not executed

for I in  " abcdefghigklmn " :
     Print (I)
     IF I == ' G ' :
         BREAK 
Print ( " end of cycle " ) 

# operation results 
A 
B 
C 
D 
E 
F 
G 
end loop
i=0
sum=0
while i<5:
    i = i + 1
    if i == 3:
        continue
    sum = sum + i
print(sum)

#运行结果
12

 

'' ' 
Prime (Prime number, also known as prime), refers to the natural number greater than 1, in addition to 1 and the number itself, but 
not by another natural number divisible (also defined as only one and the number itself two positive number factor) 
'' ' 
for I in Range (2,10 ):
     for X in Range (2 , I):
         IF I% X == 0:
             Print ( " % equal to I% x * (% i //% X) " % (I, X, I, X))
             BREAK 
    the else :
         Print ( " % I is a prime number " % (I)) 

# operation result 
2 is prime 
3 prime number 
4 is equal to 2 * (4 // 2 ) 
5 is a prime number 
6 is equal to 2* (2 @ 6 ) 
7 is a prime number 
8 equals 2 * (2 @ 8 ) 
9 equals 3 * (9 // 3)

 

The pass statement

pass an empty statement, in order to maintain the integrity of the program structure

pass without doing anything, as a general statement stations

for X in  " dshuyitrew " :
     IF ! = X ' i ' :
         pass 
        Print ( ' execution pass statement ' )
     Print ( ' i in the string ' )
     BREAK 
Print ( " end of cycle " ) 

# operation results 
performed pass statement 
i. string 
end of the cycle

 

Guess you like

Origin www.cnblogs.com/jingdenghuakai/p/11672041.html