Page 133 - TP_Prime_V2.2_Class8
P. 133

08
                                                     ALGORITHMIC

                                                     INTELLIGENCE









                                                                            Learning Objectives                             ALGORITHMIC INTELLIGENCE
                                                                            •  Multiple Conditions in a Program
                                                                            •  Loops in a Program







                                 Hey Rohan, can you explain multiple conditions and loops in coding? I know               131
                                loops repeat actions, but I don’t get how conditions work with them.


                                Sure! Multiple conditions let us check if more than one thing is true—like, if a
                               number is over 10 and even. Loops repeat actions, so if a condition’s true, the

                               loop can keep running until it’s done!

                 We learnt about writing algorithms for a program and using conditional statements in a

                 program. Let us learn multiple conditions and loops in a program.



                  Multiple Conditions in a Program


                 Conditional statements are used in a program                 Start

                 to instruct the computer to make a decision.
                 The  result  of  the  condition  will  always  be              if         False

                 either  true  or  false.  The  program  executes            condition
                 the  statements  written  after  ‘if’  when  the
                                                                           True
                 condition is true. If it is false, the statements
                                                                        Statement inside if     Statement inside else
                 written after ‘else’ will be executed.                  block will execute       block will execute


                 But there might be situations when we need
                                                                               Stop
                 to check for multiple conditions in a program.
   128   129   130   131   132   133   134   135   136   137   138