What's dose the True mean i don't know why it is being used here? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What's dose the True mean i don't know why it is being used here?

9th Apr 2018, 10:56 PM
PRINCE DIVINE
PRINCE DIVINE - avatar
3 Answers
+ 2
You'll have to show some code. While-do loops, and do-while loops, take an expression. If the expression evaluates to true, the loop will continue, otherwise if it's false, the loop will exit.
9th Apr 2018, 11:07 PM
Emma
+ 2
I'm making a wild guess that you are talking about this code in Python's loop lesson: i = 0 while True: i = i +1 if i == 2: print("Skipping 2") continue if i == 5: print("Breaking") break print(i) print("Finished") Hopefully, I'm right. Each while statement needs a condition that must be either True or False. The loop repeats until that condition becomes False. In this case, it is going to be True forever. To put True in an example, based on your user name, it would be True to say you are male and False that you are female. There are times that complex conditions decide when it is time to exit a loop so you write an infinite loop like this one. When it is time to exit, you use the break statement to do so. For this code, it doesn't really make sense to code this loop. When teaching concepts, you need simple code. Therefore, they used this example of using break to exit the loop despite the fact that almost everyone would never code it this way.
10th Apr 2018, 12:24 AM
John Wells
John Wells - avatar
+ 1
A loop will loop for as long as a set requirement remains true to its word. do { this code; } while (this condition is true); And Xan is right, we need some code to know what to help you with.
10th Apr 2018, 12:01 AM
PathFinder
PathFinder - avatar