Control Structures

Control Structures in Python:
  • In general, Control structures decide the flow of the program execution.
  • The most commonly used control structures in python are
      • Sequential: control flows through all the statements, in the order of how the code is written.
      • Selection: Depends on the condition, control flows to the different statements.
      • Iteration: Certain blocks of code(statements) will be executed repeatedly.
    Selection Statement:
    • 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 flow of program execution.
    • 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.
    • Decision making statements/selection statements available in Python are
      Looping/Iteration Statements:
      • Looping statements are used to execute a specific block of code repeatedly based on the test conditions.
      • Commonly used looping statements are
        • While loop
      Loop control statements:
      • The program flow inside the looping statements is controlled using the loop control statements.
      • Commonly used loop control statements are
        • Pass
        • Break
        • Continue
      • Break: We can terminate the loop or break away from the loop using the break statement.
      • Continue: We can skip the remaining portion of the loop statement and continue with the next iteration using the Continue statement.
      • Pass: We can use the pass statement when your code don't want to execute anything but to fill a statement syntactically.
                In an upcoming post, we will discuss each control structure.

      No comments:

      Post a comment