Page 266 - Computer Science V2.0 Class 11
P. 266

10                               CONDITIONAL STATEMENTS















                Chapter Outline


                10.1 Flow of Control in a Program                  10.2 Types of Statements in Python
                10.3 Conditional Statements







              Introduction
              So far, we have developed programs comprising Python statements that are executed in a sequence, one after the
              other. However, while solving a real-world problem, a statement may or may not be executed depending on some
              condition. For example, while moderating the results in an examination, we may add one or two marks to the marks
              obtained by a student if they are failing by a margin of one or two marks, but leave the marks unchanged in all other
              cases.
              When we execute a program, the order of execution of statements is in the same order as given in the program. This
              is the sequential flow of control in a program. However, a program may not always have a sequential flow. Sometimes,
              the execution of instructions depends on certain conditions. A set of statements may be executed multiple times or
              may not be executed even once.

              10.1 Flow of Control in a Program

              Depending on how the statements in a program are executed, the flow of control in a program can be broadly classified
              into three types:
              •  Sequential Flow
              •  Conditional Flow

              •  Iterative Flow

              10.1.1 Sequential Flow
              In a sequential flow, the statements are executed sequentially, one after the other. The linear execution of the program
              begins with the first statement of the program, continues with the rest of the statements in the same sequence as they
              appear in the program, and ends with the execution of the last statement.







               252   Touchpad Computer Science (Ver. 2.0)-XI
   261   262   263   264   265   266   267   268   269   270   271