The continue statement in python is used to bring the program control to the beginning of the loop. The continue statement skips the remaining lines of code inside the loop and start with the next iteration. It is mainly used for a particular condition inside the loop so that we can skip some specific code for a particular condition.
The syntax of Python continue statement is given below.
#loop statements continue; #the code to be skipped
i = 0; while i!=10: print("%d"%i); continue; i=i+1;
i=1; #initializing a local variable #starting a loop from 1 to 10 for i in range(1,11): if i==5: continue; print("%d"%i);
The pass statement is a null operation since nothing happens when it is executed. It is used in the cases where a statement is syntactically needed but we don't want to use any executable statement at its place.
For example, it can be used while overriding a parent class method in the subclass but don't want to give its specific implementation in the subclass.
Pass is also used where the code will be written somewhere but not yet written in the program file.
The syntax of the pass statement is given below.
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;