As shown below:
for (expression 1; expression 2; expression 3) { //loop body}First execute "Expression 1", then make the judgment of "Expression 2". If it is true, execute "loop body". After the loop body is executed, execute expression 3.
For example
for(int i=0;i<2;i++){//TODO}Execute int i = 0 first;
Then judge i<2
Then execute the function body
Finally execute i++
Then reincarnate to judge i<2
int[] arr = new int[3]; int j; arr[0] = 1; arr[1] = 2; arr[2] = 3; int searchKey = 3; for( j=0;j<arr.length ;j++){ System.out.println("j1================================================================================================================================================================; if(arr[j] == searchKey){ break; } } System.out.println("j2=========================================;Running results
j1===========0
j1============1
j1===========2
j2===========2
int[] arr = new int[3];int j;arr[0] = 1;arr[1] = 2;arr[2] = 3;int searchKey = 4;for( j=0;j<arr.length ;j++){ System.out.println("j1==============================================================================================================================================================; if(arr[j] == searchKey){ break; }}System.out.println("j2========================================;Running results
j1===========0
j1============1
j1===========2
j2===========3
Comparing the above two pieces of code and the running results, after break in the loop body, expression 3 will not be executed, that is, the last time j++ in the first block of code is not executed.
The above detailed explanation of the execution order of Java for loop is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.