AdBlock Detected

We provide high-quality source code for free. Please consider disabling your AdBlocker to support our work.

Buy me a Coffee

Saved Tutorials

No saved posts yet.

Press Enter to see all results

Python3 Loops Example – Trickcode

By pushpam abhishek
Listen to this article

Python3 Loops

The Loops condition allows to loop through the program code and repeat blocks of code until a given condition is fulfilled or not fulfilled. The code which is repeated is called the loop’s body.

There are two types of loops: the for loop and the while loop.

Loops have variables that change their values in every execution of the loop’s body and these variables have to be used as a condition either in the loop’s head or in the body to break the flow.

If you do not have a terminating condition in your loop you might end up with an infinite or endless loop that never terminates and you have to kill your application manually. Most of these loops are achieved while constructs. Let me show you examples:



while True: print('I love Python!') i = 0 while i < 1: print('I love Python!')

This loop would eventually terminate if the worth of I might be greater than 1 at just one occasion. However, because the loop’s body does only printing to the console this may never happen.

Let’s check out the loop types intimately to ascertain how loops work and the way we will avoid endless loops.
And one more nice thing about loops: they can handle an else block which gets executed if the condition in the loop’s head is not fulfilled anymore. This is a new programming construct that seems strange to programmers of a classic programming language where the loops do not have an else part.

                                  Share this article with your friends

Share this post

pushpam abhishek

About pushpam abhishek

Pushpam Abhishek is a Software & web developer and designer who specializes in back-end as well as front-end development. If you'd like to connect with him, follow him on Twitter as @pushpambhshk

Comments