Saturday, April 30, 2016

[Java] What is while(true){} in Java


 Example:
while(true) {
   //do Something
}


What is while(true){} in Java?
It's a way to create a endless loop. When true=true (It's always return true), run the statements within the while loop.

And this code do sometime same if using a flag:
boolean keepGoing = true;
while(keepGoing) {
   //do Something
}

Reference:

http://www.coderanch.com/t/592208/java/java/Meaning-true
http://stackoverflow.com/questions/6850380/are-whiletrue-loops-so-bad

No comments :

Post a Comment