In the understanding of Java while (true) of

while (true) as an infinite loop, often do not know the number of cycles when used, and will need to stop using the break in the cycle.

run () method will be written substantially while (true) cycles, as follows:

public class XXXThread implements Runnable {

public void run(){

while(true) {

……

}

}

}

  

Use role while (true) are:

run code in the method is the thread to run the code, after the run is completed, it will not run again, the method itself is not an infinite loop. And while (true) is to allow run code in the method of operation is repeated, so that the thread is running non-stop for easy viewing. If you remove, run run ends, the thread will be over.

Of course, while (true) does not run () method must, if the thread run () section need only be executed once, you do not need a nested while (true) loop.

while (true) is an infinite loop that we must add a judge within his loop when he reached what requirements will jump

int I =. 1 the while ( to true ) 
{ IF (I> 10) BREAK ; 
I ++ ; 
} // this is the last pop-up 11;







 

Guess you like

Origin www.cnblogs.com/minixiong/p/11229690.html