java keyword for: a keyword for loop control, which can be used to control statement loops.
1. The usual format is: for (initialization; control statement; control variable regulation) {loop statement}.
2. The initialization part of the control variables can be omitted, or many variables can be initialized. For example:
for(;i<100;i++)
and
for(int i=0,j=0,k=0;i<10;i++)
3. The control variable adjustment part can also be omitted, provided that you can ensure that the loop statement is not an infinite loop. For example:
for(;i<10;){i++;}
4. If the loop statement has only one sentence, you can omit the braces, such as:
for(;i<10;i++) System.out.println("xx");
5. Sometimes we can use it for delay without loop body. For example:
for(int i=0;i<100000000;i++);
6, for certain conditions can be used interchangeably with while. For example:
while(i<100)===>for(;i<100;)
PHP Chinese website, there are a large number of free JAVA introductory tutorials, everyone is welcome to learn!
The above is the detailed content of How to understand for in java. For more information, please follow other related articles on the PHP Chinese website!