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

How to understand for in java

爱喝马黛茶的安东尼
Release: 2019-12-27 11:23:19
Original
4409 people have browsed it

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++)
Copy after login

and

for(int i=0,j=0,k=0;i<10;i++)
Copy after login

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++;}
Copy after login

4. If the loop statement has only one sentence, you can omit the braces, such as:

for(;i<10;i++)
System.out.println("xx");
Copy after login

5. Sometimes we can use it for delay without loop body. For example:

for(int i=0;i<100000000;i++);
Copy after login

6, for certain conditions can be used interchangeably with while. For example:

while(i<100)===>for(;i<100;)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template