This article analyzes the execution process of the For loop in Java. Share to everyone for your reference. The specific analysis is as follows:
public class test01{public
static void Main (string[] args) {
int i = 0;
For (foo (' A '); foo (' B ') &&i<3;foo (' C ')) {
i++;
Foo (' D ');
}
public static Boolean foo (char c) {
System.out.print (c + "");
return true;
}
What is the result of this program output?
Yes, yes: a b d c b d c b d c b
Why is that so? Because the For loop executes the first semicolon before the ' a ', executes ' B ', and then executes the code in the For loop when it meets the criteria
Then jump to the second semicolon after the ' C ' this execution, and then compare ' B ' to meet the conditions, if satisfied then continue into the for loop
That is, the BDC continues to loop until the next condition is not satisfied until B is run, and the last ' B ' is output.
See here, do you have a deep understanding of the For loop?
I hope this article will help you with your Java programming.