While loop calculation rules: inner loop-outer loop !, While rule
Num = 1 # value = 1
While num <= 10: # num (1) less than 10
Print (num) # The value of this 1 should be printed
Num + = 1 # num + = 1 is equivalent to num plus 1, so this value is 2 in total.
If num = 6: # if the program is terminated for 6, if it is not up to 6, the program will go over again until it reaches 6.
Break
For example:
While num <= 10: if the value of num is 1, print 1
But in the place where mum + = 1 is executed, the value of num is added to 2
But it still does not meet the conditions for terminating the program, so the second round is required.
If we know that the value of the last num in the first round is 2, the arrival of num + = 1 will change to 3, but the termination condition is still not met,
In this case, we will continue to output the 4 and 5 items according to the above method and stop them automatically until 6.
So the final result is 12345.
While variable Determination
Age = 18 # Set the variable to 18
Sign = True # The sige variable is equal to the (True) criterion.
While sign: # while sign: Definition
Guess = int (input ("guess_age:") # guess = data filled in by the user interactive Device
If guess = age: # if the guess variable is equal to the age variable
Print ("Yes Good! ") # Print yes
Sign = False # If sign is equal to (False), the condition cannot be executed.
Elif guess <age: # If guess is smaller than age
Print ("you need to enter one bingger! ") # Print your need to neter one bigger
Else: # Otherwise
Print ("you need to enter one smaller! ") # Print you need to enter one smaller!
Print ("end! ") # End!
Break termination Determination
Age = 18
While True: # When the decision is True
Guess = int (input ("guess_age :"))
If guess = age: # if the guess value is equal to age
Print ("Yes Good! ") # Yes good!
Break # and terminate!
Elif guess <age: # Otherwise, if guess is smaller than age
Print ("you need to enter one bingger! ")
Else:
Print ("you need to enter one smaller! ")
Print ("end! ")
While loop calculation rules: