<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.
Example:
int x=1;
do
{
System.out.println("x="+x);
x++
}
while(x<3);
The program prints the following results:
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:
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)