KEMBAR78
Python Flow Control | PPTX
Python Flow Control
Python if...else
Python for Loop
Python while Loop
Python break and continue
Python Pass
Python if...else
• What are if statement in Python?
• Python if Statement Syntax
• Python if Statement Flowchart
• Example: Python if Statement
• Python if...else Statement
• Syntax of if...else
• Python if..else Flowchart
• Example of if...else
• Python if...elif...else Statement
• Syntax of if...elif...else
• Flowchart of if...elif...else
• Example of if...elif...else
• Python Nested if statements
Python if Statement Syntax
• Syntax
Python if Statement Flowchart
Example:
Output
Syntax of if...else
• Syntax
Python if..else Flowchart
Example of if...else
Output
Syntax of if...elif...else
• Syntax
Flowchart of if...elif...else
Example of if...elif...else
Output
Python Nested if statements
Output
Python for Loop
• What is for loop in Python?
• Syntax of for Loop
• Flowchart of for loop
• Example: Python for Loop
• The range() function
• for loop with else
What is for loop in Python?
• Is used to iterate over a sequence (list, tuple, string) or other iterable
objects
• Iterating over a sequence is called traversal
• Syntax of for Loop:
• Here, val is the variable that takes the value of the item inside the
sequence on each iteration
• Loop continues until we reach the last item in the sequence. The body
of for loop is separated from the rest of the code using indentation.
Flowchart of for Loop
Example
The range() function
• Can generate a sequence of numbers using range() function
• range(10) will generate numbers from 0 to 9 (10 numbers)
• Can also define the start, stop and step size as
range(start,stop,stepsize)
• Step size defaults to 1 if not provided.
• Does not store all the values in memory, it would be inefficient
• So it remembers the start, stop, step size and generates the next
number on the go
Example
for loop with else
Python while Loop
• What is while loop in Python?
• Syntax of while Loop in Python
• Flowchart of while loop
• Example: Python while Loop
• while loop with else
What is while loop in Python?
• Is used to iterate over a block of code as long as the test expression
(condition) is true
• Generally this loop is used when we don't know beforehand, the
number of times to iterate
Syntax of while Loop in Python
• Python interprets any non-zero value as True. None and 0 are
interpreted as False.
Flowchart of while Loop
Example
while loop with else
Python break and continue
• What is the use of break and continue in Python?
• Python break statement
• Syntax of break
• Flowchart of break
• Example of break
• Python continue statement
• Syntax of Continue
• Flowchart of continue
• Example: Python continue
What is the use of break and continue in
Python?
• break and continue statements can alter the flow of a normal loop
• Loops iterate over a block of code until test expression is false, but
sometimes we wish to terminate the current iteration or even the
whole loop without checking test expression
• break and continue statements are used in these cases
Python break statement
• Terminates the loop containing it
• Control of the program flows to the statement immediately after the
body of the loop.
• If break statement is inside a nested loop (loop inside another loop),
break will terminate the innermost loop
• Syntax of break
Flowchart of break
Example
Python continue statement
• Is used to skip the rest of the code inside a loop for the current
iteration only
• Loop does not terminate but continues on with the next iteration
• Syntax of Continue
Flowchart of continue
Example
Python pass statement
• What is pass statement in Python?
• Syntax of pass
• Example: pass Statement
What is pass statement in Python?
• pass is a null statement
• The difference between a comment and pass statement in Python is
that, while the interpreter ignores a comment entirely, pass is not
ignored
• However, nothing happens when pass is executed
• It results into no operation (NOP)
• Syntax of pass
Example
Example
Thank You !

Python Flow Control

  • 1.
    Python Flow Control Pythonif...else Python for Loop Python while Loop Python break and continue Python Pass
  • 2.
    Python if...else • Whatare if statement in Python? • Python if Statement Syntax • Python if Statement Flowchart • Example: Python if Statement • Python if...else Statement • Syntax of if...else • Python if..else Flowchart • Example of if...else • Python if...elif...else Statement • Syntax of if...elif...else • Flowchart of if...elif...else • Example of if...elif...else • Python Nested if statements
  • 3.
    Python if StatementSyntax • Syntax
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
    Python Nested ifstatements
  • 16.
  • 17.
    Python for Loop •What is for loop in Python? • Syntax of for Loop • Flowchart of for loop • Example: Python for Loop • The range() function • for loop with else
  • 18.
    What is forloop in Python? • Is used to iterate over a sequence (list, tuple, string) or other iterable objects • Iterating over a sequence is called traversal
  • 19.
    • Syntax offor Loop: • Here, val is the variable that takes the value of the item inside the sequence on each iteration • Loop continues until we reach the last item in the sequence. The body of for loop is separated from the rest of the code using indentation.
  • 20.
  • 21.
  • 23.
    The range() function •Can generate a sequence of numbers using range() function • range(10) will generate numbers from 0 to 9 (10 numbers) • Can also define the start, stop and step size as range(start,stop,stepsize) • Step size defaults to 1 if not provided. • Does not store all the values in memory, it would be inefficient • So it remembers the start, stop, step size and generates the next number on the go
  • 24.
  • 26.
  • 27.
    Python while Loop •What is while loop in Python? • Syntax of while Loop in Python • Flowchart of while loop • Example: Python while Loop • while loop with else
  • 28.
    What is whileloop in Python? • Is used to iterate over a block of code as long as the test expression (condition) is true • Generally this loop is used when we don't know beforehand, the number of times to iterate
  • 29.
    Syntax of whileLoop in Python • Python interprets any non-zero value as True. None and 0 are interpreted as False.
  • 30.
  • 31.
  • 33.
  • 35.
    Python break andcontinue • What is the use of break and continue in Python? • Python break statement • Syntax of break • Flowchart of break • Example of break • Python continue statement • Syntax of Continue • Flowchart of continue • Example: Python continue
  • 36.
    What is theuse of break and continue in Python? • break and continue statements can alter the flow of a normal loop • Loops iterate over a block of code until test expression is false, but sometimes we wish to terminate the current iteration or even the whole loop without checking test expression • break and continue statements are used in these cases
  • 37.
    Python break statement •Terminates the loop containing it • Control of the program flows to the statement immediately after the body of the loop. • If break statement is inside a nested loop (loop inside another loop), break will terminate the innermost loop • Syntax of break
  • 38.
  • 39.
  • 41.
    Python continue statement •Is used to skip the rest of the code inside a loop for the current iteration only • Loop does not terminate but continues on with the next iteration • Syntax of Continue
  • 42.
  • 43.
  • 45.
    Python pass statement •What is pass statement in Python? • Syntax of pass • Example: pass Statement
  • 46.
    What is passstatement in Python? • pass is a null statement • The difference between a comment and pass statement in Python is that, while the interpreter ignores a comment entirely, pass is not ignored • However, nothing happens when pass is executed • It results into no operation (NOP) • Syntax of pass
  • 47.
  • 48.
  • 49.