Page 26 - Touchcode_C7_Flipbook
P. 26

TYPES OF LOOPS
                  To execute statements multiple times till the specified condition is met, Loop is used.

                  Different types of loop are:

                  1.  While Loop
                  2.  The For Loop


                  While Loop / Conditional Loop
                  While Loop repeats a statement or group of statements when a given condition is true.
                  It tests the condition before executing the loop body.


                  The For Loop
                  For loop is used for iterating over a sequence. A for loop executes for a specific number of
                  times.


                  NESTED LOOP
                  When there is a loop inside another loop, it is called a nested loop. When one loop is nested
                  within the other, the execution of the entire program depends on the execution of the
                  innermost loop. The outer loop cannot complete its execution  until  the inner loop has

                  finished its execution.

                  APPLY LOOPS AND CONDITIONALS WITH SEQUENCING

                  Let us learn how to use loops and conditional with the help of sequencing.

                  Selection
                  Selection can be described as making a choice based on a criteria. Think of it as IF this

                  THEN that.

                  Selection is an important part of coding. It helps us to choose different paths and react to
                  situations.
                                                                                                     Life Skill and Values
                     Example: ‘Is it raining today?”

                          If the answer to the question is true, then the algorithm follows one path.
                          If the answer is false, the algorithm follows a different path.


                  Iteration

                  To run a block of code specific number of times, iteration is used. Iteration can be defined
                  as doing or repeating the same task again and again until the specified condition is met.
                  Iteration is repeating situations.





                   24     Touchcode-VII
   21   22   23   24   25   26   27   28   29   30   31