How to use WHILE in PYTHON | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to use WHILE in PYTHON

Help, please. Hiw to call WHILE in PYTHON? like this? While a => b: Print (b) ? Help please

2nd Aug 2022, 12:20 PM
ILYA
ILYA - avatar
25 Answers
+ 3
Basically, the loop construct looks like this while <condition> : # loop body But I am sure this was covered in the lesson, so tell us what did you find to be unclear? must know this so discussion can become more effective.
2nd Aug 2022, 12:24 PM
Ipang
+ 3
Yes Mr hakki .. But it can be possible that she is checking conditions ..
4th Aug 2022, 11:03 AM
Shruti Bubna
Shruti Bubna - avatar
+ 1
Don't even bother to worry about streaks, I never count it. Besides what we learn is more precious than a statistical number.
2nd Aug 2022, 12:58 PM
Ipang
+ 1
Ilya about your code, there is a much more efficient way to make an infinite loop. Instead of declaring a variable and using memory you can just say while True: print(sw) True is a boolean value. In each iteration the condition will always be positive (True) and the action in each iteration will always be performed unless the condition is False or you break the loop with the Break statement.
3rd Aug 2022, 9:37 AM
Idoredid123
Idoredid123 - avatar
+ 1
b = 0 While b < 4 Print (b) B += 1 else: Print ("loop is done")
4th Aug 2022, 12:31 PM
Youssef Hakki
Youssef Hakki - avatar
0
Ok. Thank You!
2nd Aug 2022, 12:25 PM
ILYA
ILYA - avatar
0
No problem 👌 But if you still have uncertainty, just ask away.
2nd Aug 2022, 12:31 PM
Ipang
0
Ok. In my project "Spam" I used this WHILE code while (i==1): print(sw) https://code.sololearn.com/c8z0Xvm8jf7v/?ref=app
2nd Aug 2022, 12:33 PM
ILYA
ILYA - avatar
0
And your doubt is ...
2nd Aug 2022, 12:40 PM
Ipang
0
Sorry, I cant understand You. What is DOUBT? (I am from Ukraine, and learning English)
2nd Aug 2022, 12:42 PM
ILYA
ILYA - avatar
0
Oh sorry, I mean, what is the problem that you mean to ask. The code seems to be running with no problem, although it runs infinitely, so I'm not sure where the problem is ...
2nd Aug 2022, 12:52 PM
Ipang
0
Oh. Ok. There no problem) cause thus code is called SPAM)))
2nd Aug 2022, 12:53 PM
ILYA
ILYA - avatar
0
You have 1627 days streak?
2nd Aug 2022, 12:55 PM
ILYA
ILYA - avatar
0
For me its IMPOSSIBLE)
2nd Aug 2022, 12:55 PM
ILYA
ILYA - avatar
0
While a=>b is wrong and you didn't assign value to b , while a>=b is correct
3rd Aug 2022, 9:39 AM
Om Yele
Om Yele - avatar
0
While repeat same element many times, try this: i=0 while i < 10 : print (i)
3rd Aug 2022, 10:36 AM
Владислав Роспопчук
Владислав Роспопчук - avatar
0
Bro the is you have to do like this : Example: B = 3 While b < a: Print ('b') B+=1
3rd Aug 2022, 10:46 AM
Youssef Hakki
Youssef Hakki - avatar
0
Than try with step = 1: i=0 while i < 10: print (i) i = i+1
3rd Aug 2022, 10:47 AM
Владислав Роспопчук
Владислав Роспопчук - avatar
0
Okay this I nother method but it gave you the same output okay .
3rd Aug 2022, 10:49 AM
Youssef Hakki
Youssef Hakki - avatar
0
Gg
3rd Aug 2022, 10:49 AM
Youssef Hakki
Youssef Hakki - avatar