if statement
Description: An if conditional statement is a block of code that is determined by the execution result (True or False) of one or more statements.
grammar:
if expression:
code to execute
else:
code to execute
Multi-branch if statement:
grammar:
if expression: #Execute the following code after it is satisfied
code to execute
Elif expression: #Execute the following code after it is satisfied, there can be multiple
code to execute
for loop:
Description: for in structure, iterator
Syntax: for variable in sequence:
code to execute
example:
Nesting of for loops:
example
while loop:
Description: Used for recurring tasks, such as a character in the game, you may want him to appear on the screen all the time, instead of appearing and disappearing
grammar:
while True: #The standard writing method is to write True, in fact, all non-zero and non-empty values here are True
code to execute
Example For example, we want to write a program to query students:
When we query, we may need to keep checking, instead of checking it once and then quitting, it quits when we want to quit
input is an input station, you can enter what you want to input on it, and then assign it to a variable, here if we enter 1 to exit this loop continue
Exit the entire loop when you enter 2 break