Home  >  Article  >  Java  >  What are the java loop statements?

What are the java loop statements?

coldplay.xixi
coldplay.xixiOriginal
2021-01-26 17:12:1127212browse

java loop statement: 1. while loop, the code is [while (judgment condition) {loop body (one or more statements)}]; 2. do while loop, the code is [do{loop body}] ]; 3. for loop, the code is [for (declaration of loop increment; judgment condition; increment by itself) {loop body}].

What are the java loop statements?

The operating environment of this tutorial: windows7 system, java10 version, DELL G3 computer. This method is suitable for all brands of computers.

java loop statement:

1. while loop

Basic structure

  while(判断条件){
        循环体 (一条或多条语句)
  }
  当判断条件不成立时循环结束

2. do-while loop

Basic structure

 * do{
 *      循环体
 * }while(判断条件)
 * do-while循环 不管判断条件是否成立
 * 都会先执行循环体一次

3. for loop

Basic structure

  for(声明循环增量;判断条件;增量自增){
        循环体
  }
  for(int i = 0; i < 5; i++){
        sout("循环内");
  }
    sout("循环外");

Difficulties :Nested for loop

 for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            sout("内循环");    
        }
        sout("外循环");
    }
    sout("循环外");

Related free learning recommendations:java basic tutorial

The above is the detailed content of What are the java loop statements?. 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