Process Control in Java (iii)

Source: Internet
Author: User
<title>About Process Control in Java</title> About the Process control in Java 4.do while statement

The function of the Do While statement is similar to the while statement except that it detects the value of the conditional expression after the first loop is executed, which means that the segment contained in the curly braces is executed at least once.

do
{
执行语句
}while(条件表达式语句);

Example:

int x=1;
do
{
System.out.println("x="+x);
x++
}
while(x<3);

The program prints the following results:

x=1
x=2

Note: Do and no matter how it is done at least once

5.for Loop statement
for(初始化表达式;循环条件表达式;循环后的操作表达式)
{
执行语句
}

Example:

for(int x=1;x<10;x++)
{
System.out.println("x="+x);
}

The printing results are as follows:

x=1
x=2
……
x=9
6.break and Continue statement ①break statement

The break statement can abort the execution statement and the switch statement in the loop body. A non-marking break statement passes control to the next statement in the current (most) loop (while,do,for or switch). If there is a label, the control is passed to the statement with this label in the current method.

st:while(true)
{
while(true)
{
break st;
}
}

After the break St is executed, the program jumps out of the while loop, and if the St designator is not used, the program jumps out of the while loop.

②continue statements

The continue statement can only appear in a sub-block of the Loop statement (While,do,for), and the non-labeled continue statement skips over the remaining statement block of the current loop, then executes the next loop

public  class  printoddnum  
{
< Span class= "Hljs-keyword" >public static void main (string[] args)
{
for (int i=0 ; i <10 ; i++)
{
if (I%2 ==0 )
continue;
System. out . println (i);
}
}
}

Print all odd examples between 1 and 10, when I is an even number, skips the code after this loop, executes the third part of the for statement directly, and then goes to the next loop comparison

Process Control in Java (iii)

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

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.