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

Consider the following sequence of statements in a program:

                 marks = 40                                        # Statement1
                 print(marks)                                      # Statement2
                 print("Thank You")                                # Statement3
                 In the example given above, Statement1 will be executed, followed by Statement2 and then Statement3. Therefore,
                 the output produced on the execution of the above code will be:
                 40
                 Thank You
                 The flow of control in the above example may be depicted using Fig. 10.1.


                                                                Statement 1





                                                                Statement 2





                                                                Statement 3

                                                      Fig 10.1: Sequential Flow of Control

                 10.1.2 Conditional Flow
                 Suppose the pass percentage (Maximum Marks is 100) for an examination is 30. So, a student  passes the examination
                 if he/she gets marks above the pass percentage and fails otherwise. Hence, the output will depend on the marks
                 obtained by a student. We can display the result of a student who secured 44 marks in this examination as follows:
                     marks = 44
                     passPercentage = 30
                     if marks >= passPercentage:
                         print("Passed")
                     else:
                         print("Failed")
                 In case of conditional flow, the execution of the statements depends upon a conditional expression. If evaluation of the
                 conditional expression yields True, a particular sequence of statements is executed, otherwise, another sequence
                 of statements may be executed. Such statements in a program are known as conditional, selection, or branching
                 statements.





                                                                  False
                                                  Test                   Statement(s) to be executed if
                                                Condition                      condition is False



                                                     True


                                        Statement(s) to be executed if        End of if statement
                                             condition is True

                                                      Fig 10.2: Conditional flow of Control

                                                                                               Conditional Statements  253
   262   263   264   265   266   267   268   269   270   271   272