Home  >  Article  >  Java  >  How to understand for in java

How to understand for in java

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-12-27 11:23:194389browse

How to understand for in java

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does java t mean?Next article:What does java t mean?