python learning eight (while loop)

Loops
  Loops can specify the code block number specified eating
  loop is divided into two kinds, while loop, a for loop and
  while loop
  syntax:
    while conditional expression:
      block
    else:
      block
  execution flow:
    while statement execution that would first conditional expression is evaluated while the determination, if the determination result is True, the loop body is executed (block)
    the loop is finished, a conditional expression evaluated value determination, and so on, until the determination results false, the loop terminates
  as:
  I = 0
  the while I <10:
    Print ( "Hello")
  the else:
    Print ( "end code!")
  I + =. 1

break break loop

 

import random # obtain a random number function 
SUM1. 1 =
NUM the random.randint = (. 1, 100) # 100 to obtain a random number within
the while. 1> 0:
SUM1 + =. 1
userNum = int (INPUT ( "Please enter a number : "))
IF userNum <NUM:
Print (" your number of small ")
elif userNum> NUM:
Print (" your big number ")
elif userNum == NUM:
Print (" you win ")
BREAK # break loop
the else:
Print ( "enter a number")

 

continue skip this recirculation cycle

= 0 sum100 
counter = 0
the while counter <100:
counter + 1 =
IF counter 2%: # remainder can only be 1 or 0 is True, 0 is False
Continue # skip this cycle
sum100 + = counter
Print (sum100 )

 

Guess you like

Origin www.cnblogs.com/wangwen022/p/11299128.html