Python Tutorial ( PDFDrive )

28.10.2021 Views

breakFlow Diagram: Example: #!/usr/bin/pythonfor letter in 'Python': # First Exampleif letter == 'h':breakprint 'Current Letter :', lettervar = 10# Second Examplewhile var > 0:print 'Current variable value :', varvar = var -1if var == 5:breakprint "Good bye!"When the above code is executed, it produces the following result:Current Letter : PCurrent Letter : yCurrent Letter : tCurrent variable value : 10Current variable value : 9Current variable value : 8Current variable value : 7Current variable value : 6Good bye!TUTORIALS POINT Simply Easy Learning

continue statement The continue statement in Python returns the control to the beginning of the while loop. The continue statementrejects all the remaining statements in the current iteration of the loop and moves the control back to the top of theloop.The continue statement can be used in both while and for loops.Syntax: The syntax for a continue statement in Python is as follows:continueFlow Diagram: Example: #!/usr/bin/pythonfor letter in 'Python': # First Exampleif letter == 'h':continueprint 'Current Letter :', lettervar = 10# Second Examplewhile var > 0:var = var -1if var == 5:continueprint 'Current variable value :', varprint “Good bye!”When the above code is executed, it produces the following result:Current Letter : PTUTORIALS POINT Simply Easy Learning

break

Flow Diagram:

Example:

#!/usr/bin/python

for letter in 'Python': # First Example

if letter == 'h':

break

print 'Current Letter :', letter

var = 10

# Second Example

while var > 0:

print 'Current variable value :', var

var = var -1

if var == 5:

break

print "Good bye!"

When the above code is executed, it produces the following result:

Current Letter : P

Current Letter : y

Current Letter : t

Current variable value : 10

Current variable value : 9

Current variable value : 8

Current variable value : 7

Current variable value : 6

Good bye!

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!