Page 135 - TP_Prime_V2.2_Class8
P. 135

21 st
                      Warm              Write the result for the following conditions:             Century   #Critical Thinking
                                                                                                     Skills
                      Up!
                                              day ="Sunday"                    height_inch=46
                                                                               ticket ="no"
                                              IF day = "Saturday" OR day=
                                              "Sunday" THEN                    IF height_inch > 40 AND ticket =
                                                                               "yes" THEN
                                                   PRINT "It's a holiday"           PRINT "Entry allowed"
                                              ELSE                             ELSE                                         ALGORITHMIC INTELLIGENCE

                                                   PRINT "It's not a holiday"       PRINT "Entry not allowed"









                                                                                                                          133
                  Loops in a Program


                 A loop allows a set of instructions or a block of code to be executed repeatedly. It helps in
                 automating repetitive tasks and makes the code more efficient by avoiding the need to write
                 the same instructions multiple times. When a loop repeats forever (endlessly), it is called an
                 infinite loop. There are two types of loops.

                 •   Counting loops: These repeat a block of code a certain number of times.

                 •   Conditional loops: These repeat until a certain condition is reached, which means they
                    keep going until the condition remains true.

                 For example:
                 Robby has to paint these blank boxes to make a letter ‘U’
                                     Start                               Start















                                                   Just as plants need sunlight
                                                  to produce glucose, algorithms
                                                   need right data to generate
                                                         optimum results.
   130   131   132   133   134   135   136   137   138   139   140