Page 499 - ComputerScience_Class_11
P. 499

Output

                        1
                       1 2
                      1 2 3
                     1 2 3 4
                    1 2 3 4 5





                 Loop Control Statements
                 Loop control statements in Python are used to control the flow of execution within loops. These statements can be
                 used to modify the normal flow of a loop, such as skipping an iteration, stopping the loop entirely or jumping to the
                 next iteration. Python provides three primary loop control statements:

                 •  break
                 •  continue
                 •  pass

                 Break Statement
                 The break statement is used to terminate the loop immediately, regardless of whether the loop's condition is true or
                 not. When the break statement is encountered, the loop stops and the program continues with the next line of code
                 after the loop.

                 Syntax:
                 for variable in sequence:


                     if condition:
                         break  # Exit the loop if the condition is met
                     # other code
                 Program 8: Write a program to print the numbers using break statement.
                     Program 8.py

                  File  Edit  Format   Run   Options   Window     Help

                  for i in range(1, 11):
                      if i == 6:
                          break
                      print(i)




                     Output

                  1
                  2
                  3
                  4
                  5






                                                                                                    Flow of Control  497
   494   495   496   497   498   499   500   501   502   503   504