while (true) how to exit the loop __string

Source: Internet
Author: User

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");
}

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.