+ 2

While loop

Hello guys , can anyone tell me what is the "while" loop function in python and how to use it.

28th Aug 2024, 7:37 AM
Mehul Vaity
Mehul Vaity - avatar
6 Answers
+ 3
In the python courses, it is explained that the "while loop" is used when you don't know the exact number of times the loop must run, and this is the main difference with the "for loop", which needs an exact number of times to run. Two ways to loop based on the situation you are facing. Study the three python courses and you'll find plenty of information.
28th Aug 2024, 6:34 PM
Ruben
+ 3
Ruben , be careful when saying about a for loop: ... which needs an exact number of times to run ... you can exit a for loop at any time with a break statement.
28th Aug 2024, 6:42 PM
Lothar
Lothar - avatar
+ 2
The while loop in Python is used to repeatedly execute a block of code as long as a condition is true. Here’s a simple example: count = 0 while count < 5: print("Hello") count += 1 In this example, the while loop will print "Hello" as long as the value of count is less than 5. With each iteration, count increases by 1, and once it reaches 5, the loop stops. This is useful when you want to repeat certain actions until a specific condition is met.
28th Aug 2024, 8:18 AM
Melkon
Melkon - avatar
+ 2
MUNTASIR SAMI , (the following description is valid for the android app) > to start with the tutorial `introduction to python`, go to the learn section. on the top of this page, you can select all available tutorials there. select `introduction to python` and start learning. if you get stuck somewhere, you can post a question in the `q&a` section.
29th Aug 2024, 3:30 PM
Lothar
Lothar - avatar
+ 1
Mehul Vaity , > here is a link to a short tutorial about while loops that comes from the community section of sololearn. https://www.sololearn.com/learn/o-JUMP_LINK__&&__Python__&&__JUMP_LINK/2281/?ref=app > the loops are also explained in the various python tutorials. so maybe you are going to finish the `introduction to python` ?
28th Aug 2024, 10:58 AM
Lothar
Lothar - avatar
+ 1
Hi i want to learn python how can i learn python please help me
29th Aug 2024, 3:02 PM
MUNTASIR SAMI
MUNTASIR SAMI - avatar