The continue announcement in Python is used to carry the software control to the opening of the loop. The continue announcement skips the last traces of code inner the loop and begin with the next iteration. It is broadly speaking used for a precise condition inside the loop so that we can bypass some specific code for a unique condition.The continue statement in Python is used to carry the program manage to the commencing of the loop. The proceed statement skips the ultimate lines of code internal the loop and begin with the subsequent iteration. It is more often than not used for a unique situation inside the loop so that we can pass by some precise code for a particular condition.
#loop statements continue #the code to be skipped
Consider the following examples.
i = 0 while(i < 10): i = i+1 if(i == 5): continue print(i)
1 2 3 4 6 7 8 9 10
Observe the output of above code, the price 5 is skipped because we have furnished the if condition the use of with proceed statement in whilst loop. When it matched with the given condition then manipulate transferred to the establishing of the whilst loop and it skipped the cost 5 from the code.
Let’s have a look at another example:
str = "JavaTpoint" for i in str: if(i == 'T'): continue print(i)
J a v a p o i n t
The bypass statement is a null operation considering the fact that nothing happens when it is executed. It is used in the instances where a announcement is syntactically wished but we don’t desire to use any executable statement at its place.
For example, it can be used whilst overriding a mum or dad category technique in the subclass however don’t choose to supply its particular implementation in the subclass.
Pass is also used where the code will be written somewhere however not but written in the application file. Consider the following example.
list = [1,2,3,4,5] flag = 0 for i in list: print("Current element:",i,end=" "); if i==3: pass print("\nWe are inside pass block\n"); flag = 1 if flag==1: print("\nCame out of pass\n"); flag=0
Current element: 1 Current element: 2 Current element: 3 We are inside pass block Came out of pass Current element: 4 Current element: 5
We will research extra about the bypass declaration in the subsequent tutorial.