Jump statements can be used to modify the behaviour of conditional and iterative statements.
break
and continue
statements fall under the jump statements category.
break
statement
- The
break
statement, borrowed from C programming language, breaks out of the current loop when encountered. - So, any further iterations will not be executed as the
break
statement changed the flow of the program by coming out of the loop.
Output:
Searching...
Searching...
Searching...
Searching...
Found the treasure
continue
statement
- The
continue
statement, borrowed from C programming language, continues with the next iteration of the loop when encountered. - So, any code following the
continue
statement in a loop will be skipped and the loop will continue the next iteration.
Output:
Found an even number 2
Found an odd number 3
Found an even number 4
Found an odd number 5
Found an even number 6
Found an odd number 7
Found an even number 8
Found an odd number 9
Best Resources
Python Blog Series : A Blog series where I will be learning and sharing my knowledge on each of the above topics.
Learn Python for Free, Get Hired, and (maybe) Change the World! : A detailed roadmap blog by Jayson Lennon (a Senior Software Engineer) with links to free resources.
Zero To Mastery Course - Complete Python Developer : A comprehensive course by Andrei Neagoie (a Senior Developer) that covers all of the above topics.
Who Am I?
I’m Aswin Barath, a Software Engineering Nerd who loves building Web Applications, now sharing my knowledge through Blogging during the busy time of my freelancing work life. Here’s the link to all of my socials categorized by platforms under one place: https://linktr.ee/AswinBarath
Thank you so much for reading my blog🙂.
Top comments (0)