In this article, we will learn about Loops and Control Statements (continue, break and pass) in Python 3.x. Or earlier.
Python offers to loop constructs i.e. for & while. Unlike other languages, the for loop is not constrained by any conditional before its execution. Here for loop uses range function for its execution and iteration.
Let’s have a look at their implementations −
i = 0 while (i < 4): print("Tutorialspoint") i=i+1
Tutorialspoint Tutorialspoint Tutorialspoint Tutorialspoint
for i in "Tutorialspoint": print(i,end=" ")
T u t o r i a l s p o i n t
for i in range(1,5): print(i)
1 2 3 4
Now let’s see the implementation of jump statements −
for i in 'Tutorialspoint': if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u': continue else: print ('Character :', i)
Character : T Character : t Character : r Character : l Character : s Character : p Character : n Character : t
for i in 'Tutorialspoint': if i == 'a' or i == 'e' or i == 'i' or i == 'o' : Break else: print ('Character :', i)
Character : T Character : u Character : t
for i in 'Tutorialspoint': if i=='u' or i=='p': pass else: print ('char :', i)
char : T char : t char : o char : r char : i char : a char : l char : s char : o char : i char : n char : t
In this article, we learned about looping constructs, jump statements and bypass statements available in Python 3.x. Or earlier.