0
What is use of while (false) while(true) and how to use it?
8 Antworten
+ 9
If the condition in true then it will enter the while loop. Otherwise , it will skip the while.
+ 6
I'm not sure of a use for while (false), even if it were used in a do/while to run at least one time.
while (true) can be useful for unpredictable loops that depend on things like user input, random numbers, files, etc.. With whatever condition(s) you set to leave the loop, you use the keyword break to exit the loop when they're met. Example:
while (true)
{
//your code
//Y/N loop
if (yn.ToUpper() == 'N') break;
}
It's the same as if a condition had been put at the top instead, like
while(yn.ToUpper() == 'Y')
so it's a matter of preference where you want it.
+ 4
false to skip this loop only.
+ 2
while loops use only Boolean expression and when it is true. So when it gets true it'll execute until it gets false.
while(false) means the condition is false which will end the loop.
while(True) means the condition is True which will continue the loop.
+ 1
while(true) in an infinite loop
0
while (true) is covered by Tamra, while(false) could be used to temporarily skip the while loop when debugging code.
0
dowhile loop execution at least one time not matter conditions true or false
0
Which condition is the while loop checking to be true or false?