Java Technology Basics (loop)

Loop:
(. 1) for (int I = integer [number of starting cycles]; i <integer [end of the loop]; i ++ / i -) {
execute statement
}
for the first loop to determine the start value (values are integer), and then determine the cycle settlement conditions (relational operator), or tired accumulated set start value Save
when the circulation is stopped when the loop condition is not satisfied, note that generally makes use condition is not satisfied or will reach dead cycle

(2) while loop
while (relational expression) {
statements executed
}
when the relationship expression returns true if the execution cycle is instead stop the loop

int i = 0;
boolean flag = true;
While(flag){
	System.out.println(“aaa”);
	i++;
	If(i>10){
		flag = false;
}
} //执行十次aaa

often used for relatively fixed number of cycles, the condition is typically an integer
while under cycling conditions typically more complicated situations (e.g., complex logical expressions)
the number and the cycle is not fixed

(. 3) do {
}
the while (logical expression);

int i = 10;
do{
	System.out.println(“aaa”);
}while(i<10);

and while the difference between do while
when the loop condition is not met: while a loop is not executed contents; will do while performing at least once
executed while the determination is the first
after the first execution judgment is do while

Published 30 original articles · won praise 10 · views 1956

Guess you like

Origin blog.csdn.net/helo_world01/article/details/104738578