While can be used as an infinite loop, many places use infinite loops. An infinite loop looks like this:
}
An infinite loop can be terminated by one of the conditional expressions in its own loop. Here is an example of a loop internal termination:
while (true) {
Break ; Jump off Loop
...
When the conditional is set up, the break leaves the while loop, which is the same as the switch, and is used when you want to leave the program block that was executed.
Class Testwhile
{
public static void Main (string[] args)
&nbs p; {
while (true)
{
System.out.println ("execution");
// Value is a statement that jumps out of the execution while with a break
if (true)
{
Break
}
SYSTEM.OUT.PRINTLN ("continued execution");
}
}
}
The infinite loop has a fixed format of while (true), where the value in parentheses is fixed to a Boolean, and the following statement is executed to be true.
Class Testwhile
{
public static void Main (string[] args)
{
Boolean flag = false;
while (flag)//When the value in parentheses is false, the following statements are not executed. If you change to a while (!flag) you can do it.
{
System.out.println (Execute while true);
Value is true with break jump out of execute while statement
if (true)
{
Break
}
SYSTEM.OUT.PRINTLN ("continued execution");
}
}
}