1.

Explain pass, continue and break statements in Python?

Answer»

In Python, loops statements are used in order to do repetitive tasks with good efficiency. But in some scenarios, we need to come out of those loop statements or ignore some of the conditions. For these scenarios Python provides various loop control statements in order to take control over loops. These statements are as below.

  • Break statement
  • Continue statement
  • Pass statement
  1. Break statement: Break statement is a loop statement which is used for the purpose of breaking or terminating the loop in which it has been APPLIED. After the application of this statement to a loop, the control will be shifted to the next consecutive statement to the break statement if available. If Break statement is applied to a nested loop, then it will break only those particular loops where it has been applied.
  2. Continue statement: Continue statement is a loop statement which is exactly opposite to the behaviour of break statement. It continues to execute the next iteration of the loop rather than breaking or terminating that loop. In SHORT words, it helps in terminating current iteration and continue to execute the next iteration of a loop. When a Continue statement is executed in a loop, then the whole code inside the loop will be skipped and the control will shift to next iteration of loop.
  3. Pass statement: Pass statement is a loop statement which when executed does nothing. When a particular statement is required syntactically but at the same time no code needs to be executed then we can use this Pass statement. Empty loops can be EASILY written with the help of Pass statement. It can also write FUNCTIONS and CLASSES.


Discussion

No Comment Found