Page 80 - CloudGPT_C8_Flipbook
P. 80

EXIT CRITERIA
                  A looping condition must get false at a certain point of time, else the block of code will enter

                  in an infinite loop. For this it is important to define an exit criterion for the loop.

                  An exit criteria is a condition which must be met before completing a specific task. It is a set
                  of conditions that must exist before when you can declare a program to be complete.

                  Exit criteria differ from program to program as per the requirement.

                  Let’s understand the concept of exit criteria, by taking an example of creating a loop to print
                  numbers from 1 to 100  exit criteria in this situation, is that the loop should exit the block
                                            th
                  of code when the 100  number is printed, else the program will enter in an infinite loop.
                                          th

                  JUMP STATEMENTS
                  While executing a program sometimes
                  we need to change the flow of the            While (Loop-Condition)

                  program. To do so, we need change            {
                  the flow of control from one part of the        Statement 1;
                  program to another. For this we can             Statement 2;
                                                                  ...........
                  use break and continue statements.                                 Execution  of the program
                                                                  Break;             skips    after   the    break

                  Break Statement                                 ...........        statement is encountered in
                                                               }
                  The break statement alters or change         Statement             the loop body.
                  the normal flow of execution of the

                  statement by terminating the existing
                  loop and continues the execution of the statement following that loop.

                  Break statement is used to come out of a loop early when the specific condition is met.

                  In break, the control skips the lines after the break statement is found and executes the first
                  statement outside the loop.
                                                                                                        Critical Thinking

                    Example 1: Program to print number from 7 to 4, and another print
                    statement when you encounter break.

                  Pseudocode:
                  Program Start

                  set value of a to 7
                  while the value of a is greater that 0
                         display 'Current variable is: ' value of a

                         decrease the value of a by 1
                         if value of a is equal to 4

                   78     Premium Edition-VIII
   75   76   77   78   79   80   81   82   83   84   85