Home  >  Article  >  Java  >  What does for in java mean?

What does for in java mean?

(*-*)浩
(*-*)浩Original
2019-11-15 10:04:033912browse

What does for in java mean?

for, a guide word for a loop structure

for keyword is used to specify a value in each iteration A loop that checks its condition before ending.                                                                                             (Recommended learning: java course )

for loop, making some loop structures simpler. The number of times the for loop is executed is determined before execution.

The syntax format is as follows:

for(初始化; 布尔表达式; 更新) {
    //代码语句
}

There are several instructions for the for loop:

The initialization step is performed first. A type can be declared, but one or more loop control variables can be initialized, or it can be an empty statement.

Then, detect the value of the Boolean expression. If true, the loop body is executed. If it is false, the loop terminates and execution of the statements following the loop body begins.

After executing a loop, update the loop control variables.

Detect Boolean expression again. Perform the above process in a loop.

Example

public class Test {
   public static void main(String args[]) {
 
      for(int x = 10; x < 20; x = x+1) {
         System.out.print("value of x : " + x );
         System.out.print("\n");
      }
   }
}

The compilation and running results of the above example are as follows:

value of x : 10
value of x : 11
value of x : 12
value of x : 13
value of x : 14
value of x : 15
value of x : 16
value of x : 17
value of x : 18
value of x : 19

The above is the detailed content of What does for in java mean?. 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