Friday, 20 July 2012

The Continue Statement:


The continue statement in Python returns the control to the beginning of the while loop. The continue statement rejects all the remaining statements in the current iteration of the loop and moves the control back to the top of the loop.
The continue statement can be used in both while and for loops.

Example:

#!/usr/bin/python
For letter in ‘Python’ :               # First Example
            If letter  ==  ‘h’:
                continue
            Print  ‘Current  Letter  : ‘ ,  letter

var  = 10
while  var  > 0:
     var  =  var -1
    if  var  ==  5:
            continue
     print  ‘Current   Variable Value  :’, letter
print  ”Good bye !”

This will produce following result:

Current Letter :  P
Current Letter :  y
Current Letter :  t
Current Letter :  h
Current Letter :  o
Current Letter :  n
Current Variable Value : 10
Current Variable Value :  9
Current Variable Value :  8
Current Variable Value :  7
Current Variable Value :  6
Current Variable Value :  5
Current Variable Value :  4
Current Variable Value :  3
Current Variable Value :  2
Current Variable Value :  1
Good bye!

No comments:

Post a Comment