The process of changing the order of program runs through conditional or circular statements is called Process Control.
Conditional statements
Conditional statement: Used to change the execution flow of the program, where the else code block is optional.
1.if/else
1PWD = Raw_input ("What ' s the password?")2 ifPWD = ='Apple':3 Print "loging on ..."4 Else:5 Print "Password error!"6 Print " All done"
2. Upgrade Version If/elif
1PWD = Raw_input ("How is old is you ?")2 ifAge <= 12:3 Print ' Free'4 elif< Age < 16:5 Print 'Child Fare'6 Else :7 Print 'Adult Fare'
Looping statements
Looping statements: Used for repeating code blocks, mainly for loops and while loops, where the For loop is easier to use than while and while is more flexible.
The For loop is more suitable for situations where the condition is known and the number of loops is fixed, while loops are more suitable for situations where conditions are uncertain, while loops are more than one variable declaration in the For Loop memory.
1.for Loop, execute n times
1 for in range:2 print i
2.while Loop, executes n+1 times until the last one is False
1 i = 02 while I <:3 print i 4 i = i + 1
3. Interrupt loop, continue interrupt this cycle, break interrupts the entire cycle
1 #when the loop executes to I = 2, the If condition is set, the continue is triggered, the execution is skipped (no print is executed), and the next execution is resumed (i = 3)2 forIinchRange (10):3 ifi = = 2:4 Continue5 PrintI6 7 #when the loop executes to I = 2, the If condition is set, the break is triggered, the entire loop ends8 forIinchRange (10):9 ifi = = 2:Ten Break One PrintI
Basic knowledge review--Process Control