Page 273 - Computer_Science_F5
P. 273

Computer Science  depending on its score. The syntax of the nested if statement.
                 If (condition 1)
                 {
                 // this block will execute when condition 1 is true.
                 statement 1
          FOR ONLINE READING ONLY
                 }
                 else if (condition 2)
                 {
                 //this block will execute when condition 2 is true.
                 statement 2;
                 }
                 else if (condition 3)
                 {
                 //this block will execute when condition 3 is true.
                 statement 3;
                 }
                 else
                 {
                 //this block will execute if no any condition is true.
                 default-statements;
                 }


           Figure 4.42 shows the execution flowchart of Nested if statement.




                           True                 False
                                   Condition 1

                   Statement 1
                                           True  Condition 2  False



                                                    True              False
                                     Statement 2           Condition 3


                                              Statement 3            Default statement








                                     Figure 4.42: Nested if …..flow chart


                                                 264
                                                                for Advanced Secondary Schools



     Computer Science Form 5.indd   264                                                     23/07/2024   12:34
   268   269   270   271   272   273   274   275   276   277   278