Navbar menu

For loop

What is For loop in Python?
  • A for loop in python has the ability to iterate over items of any sequence (List, tuple, string) or any other iterable objects.
  • Iterating over a sequence is called traversal.
Syntax:
                    for var in sequence:
                            body statements
    
  • Here, var is a variable that is used to take the next values from the sequence on every iteration until the end of the sequence is reached.

If, If...else, If...elif...else, Nested If

What is a selection statement in Python?
  • In some cases in programming, Our program has to decide whether the following block of codes needs to be executed or not, based on some conditions.
  • Such Decision making statements/selection statements decide the direction of the flow of program execution.
  • Decision making statements/selection statements available in Python are
        • if (Simple If)
        • if-else
        • else-if ladder
        • Nested if
  • In python, body statements inside the selection statement are indicated by the indentation. The very first unindented line marks the end of the selection statements.