while (true)
{
操作;
}
And
do{
操作;
}while (True)
It acts on the loop of operation in curly braces, so long as the condition is judged as "true", it can be cycled forever.
So write to the loop condition of the operation, otherwise it will die loop, cause the subsequent operation cannot execute.
There is a difference between the two while:
while () is first judged in execution,
Do{...} while () is performed first in the judgment.
The for (variable initial value; cyclic condition; variable change) is based on the while and adds the control of the number of cycles.
Example:
for (i==0;i<100;i++)
{
SYSTEM.OUT.PRINTLN ("Study hard!") ")
}
Result: Show "study hard!" "Shown 100 times.
Tip: In the case of uncertain cycle times, using while is more appropriate, but for the number of cycles known to use for more convenient.
Java: Using while () and do....while with for ()