Python Control Flow
if Statements
The if statement is used for conditional execution
The while statement
The while statement is used for repeated execution as long as an expression is true
for Statements
In Python’s for statement iterates over the items of any sequence (a list or a string)
The range() Function
If you do need to iterate over a sequence of numbers, the built-in function range() comes in handy. It generates arithmetic progressions
Output
More example on range
break and continue Statements
The break statement, breaks out of the innermost enclosing for or while loop
The continue statement, continues with the next iteration of the loop:
Break
Continue
Define function
Functions are used to utilize code in more than one place in a program
if Statements
The if statement is used for conditional execution
The while statement
The while statement is used for repeated execution as long as an expression is true
for Statements
In Python’s for statement iterates over the items of any sequence (a list or a string)
The range() Function
If you do need to iterate over a sequence of numbers, the built-in function range() comes in handy. It generates arithmetic progressions
Output
More example on range
The break statement, breaks out of the innermost enclosing for or while loop
The continue statement, continues with the next iteration of the loop:
Break
Continue
pass Statements
The pass statement does nothing. It can be used when a statement is required syntactically but the program requires no actionDefine function
Functions are used to utilize code in more than one place in a program
Comments
Post a Comment