Loops allow you to execute a statement or group of statements repeatedly. Loop Architecture Python programming language has two typed of loop
Repeats a statement or group of statements while a given condition is True. It tests the condition before executing the loop body.
Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.
The Loop control statements change the execution from its normal sequence. When the execution leaves a scope, all automatic objects that were created in that scope are destroyed. Python supports the following control statements.
breakbreaks the loop routine and python would run the statement right after the loop
continuecontinues the loop from the beginning , skipping the rest of the statement within the loop.
passpass is not strictly a loop control, its a general keyword used for "Do nothing" just syntactically used.
#!/usr/bin/env python list = [1,2,3,4] it = iter(list) # printing items of the iterator for x in it: print (x) # you can printing items of the list directly for x in list: print (x) # printing the first item only for x in it: print (x) break # printing nothing for x in it: break print (x) # printing nothing for x in it: continue print (x) # you can use next() function while True: try: print (next(it), end=' ') except StopIteration: pass