Page 500 - ComputerScience_Class_11
P. 500

Explanation: The loop iterates over numbers from 1 to 10.
              The if i == 6: condition checks if i is equal to 6. When this condition is true, the break statement is executed, which
              stops the loop immediately.

              Continue Statement
              The continue statement is used to skip the current iteration of the loop and jump to the next iteration. When continue
              is executed, the rest of the code inside the loop for that particular iteration is skipped and the loop moves on to the
              next iteration.
              Syntax:

              for variable in sequence:

                  if condition:
                      continue  # Skip the current iteration

                  # other code
              Program 9: Write a program to print the numbers using continue statement.

                   Program 9.py
               File  Edit  Format    Run   Options   Window    Help


                for i in range(1, 11):
                    if i == 5:
                        continue
                    print(i)




                   Output

                1
                2
                3
                4
                6
                7
                8
                9
                10



              Explanation: The loop iterates over numbers from 1 to 10. When i equals 5, the continue statement is executed, which
              skips the print(i) statement for that iteration and moves to the next iteration of the loop.

              Pass Statement
              The pass statement is a placeholder that does nothing. It is used when a statement is syntactically required, but you
              don't want to execute any code. This can be useful when you're planning to write code later but want to avoid errors
              during development.








                  498  Touchpad Computer Science (Ver. 3.0)-XI
   495   496   497   498   499   500   501   502   503   504   505