Session -5(Loops)

In this session , I’ll cover below topics following by some assessments

  • Loops
  • While Loop
  • Infinite Loop
  • Single Statement While Suites

1.Loops

  • Execute statement(s) more than ones
  • Until condition is True or non-zero value
  • Exits when condition is False or zero
  • Nested loops : loops ← loops
  • Loop statements
    • –> while
    • –> for

2.While Loop

while loop statement in Python programming language repeatedly executes a target statement as long as a given condition is true.

The syntax of a while loop in Python programming language is −

while expression:
   statement(s)

Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any non-zero value. The loop iterates while the condition is true.

When the condition becomes false, program control passes to the line immediately following the loop.

3.Infinite Loop

An infinite loop, is characterized by not having an explicit end, unlike the finite ones exemplified previously, where the control variable i clearly went from 0 to 9 (note that at the end i = 10, but that value of i wasn’t printed). In an infinite loop the control is not explicitly clear, as in the example appearing here:

  • while (non-zero) — > Statements

4.Single Statement While Suites

  • One line while loop
  • while clause contains only one statement
  • Single line while code block

Leave a comment