In this article, we are telling you about For loop and While Loop in Python, while Loop in Python, For loop in Python you must have done some search at some time.
Here we are telling you about For loop and While Loop in Python by making practical program, why and when they are used, it is being told to you here.
For loop and while Loop is used in almost all types of programming languages, you must have heard about it at some time or all of this, it is also used in creating tools.
What is Loop in Python
Before going about For loop and While Loop in Python, you should know what the loop is like, when we have to print something repeatedly in the program, loop is used in this way.
Let us understand this by example, as we have to print freelearningtech 10 times in the program, in this way we can do this easily by using For loop and While Loop in Python.
You also have to use the loop to make tools for Hacking at some time, so you must know about the loop when you deeply learn python or any kind of programming language, only then you can use them properly.
Also Read
Open Source Intelligence tools
While Loop In Python ?
Let us now know about While Loop in Python, here we would like to tell you one thing while Loop in Python is used like in most of the way in many languages like while loop is used.
![While Loop in Python ?](https://freelearningtech.in/wp-content/uploads/2020/09/cdbfgv.png)
As you can see in the program, you can print it as many times as you want by using While Loop in Python in this way, but here you should know why it happens, let’s know about it.
As here the variable is i, followed by the while condition, it works as long as the condition remains true as long as the while loop runs, you can see that i = i +1 is given.
If you understand this in easy language, then you can understand that as long as the value of i is 10 then the loop runs on us but as soon as i has value 11 your loop stops.
![While Loop in Python ?](https://freelearningtech.in/wp-content/uploads/2020/09/fvedfnfg.png)
Here you can also print the value of i as you can see in the image, in this way you can also print the value of i and see how long your loop lasts.
Infinite Loop
In the same way you can also use infinite loop like in the while loop in python you have been told how we can print a value as many times as you want.
But if you want to print the value continuously, infinite loop is used in such a way that you can see in the program, here we have given the value 0 of i and neither have we defined
![While Loop in Python ?](https://freelearningtech.in/wp-content/uploads/2020/09/vdfhngb.png)
In this case, your loop keeps running continuously until you stop the loop manually, here you have to use ctrl + c to stop the infinite loop manually.
![For loop and While Loop in Python ?](https://freelearningtech.in/wp-content/uploads/2020/09/fehghgrd.png)
In this way, you can also see in this program how the infinite loop is used, here we have made the condition of While true and have not declared any value, in such a way your loop continues.
Here you can run the infinite loop both ways as you can see both the programs are different but the output is getting the same kind of something, infinite loop is used in this way.
For Loop in Python ?
Let us now know about for loop in python as you have been told while syntax of while loop is similar to you in almost all programming languages but you get different syntax for loop.
Best Programming Language For Hacking ?
As you can see in the image, for this way for loop is used in python here we have decided the range as if you can see the range of i is given 10, in such a way your for loop runs till 10.
![For loop and While Loop in Python ?](https://freelearningtech.in/wp-content/uploads/2020/09/fcedgbfv.png)
Just as in the while loop in python you can print the value of i, in the same way the value of i can also be printed in the for loop here while while loop and for loop are used to print a value more often.
![](https://freelearningtech.in/wp-content/uploads/2020/09/cedhfngvb.png)
As you can see while loop in python and for loop in python are both used differently but the output is always the same, in such a way you can use both in your program.
The Conclusion
I hope now you can understand about while loop in python and for loop in python. Here we have told you the basic use of both of them, while the same can be used with while loop.
Similarly, the use of nested can also be done with them, it will be told to you further, but before learning all that, you should know the basic use of While loop in python and for loop in python.
We have told you by making a use program of both, you can also see using the same loop, if you face any problem in using the loop, you can ask in the comment.
If you like this article of ours, share it in such a way, you can ask any kind of questions related to your Hacking, we will help you completely. Subscribe to our blog for latest updates
Here you get knowledge about all the modules of CEH such as Website Hacking, Android Hacking, IOT Hacking and IOT devices, if you wish, you can also read our article.
Sharing is Caring
Thankyou
Leave a Reply