JAVA basics/Lesson 17th: control procedures/java while and DO-WHILE and FOR loop statements, whiledo-while
1. Repeated execution when the condition is true
As long as the expression in the while clause is true, it will be continuously executed cyclically.
Public class HelloWorld {public static void main (String [] args) {// print 0 to 4 int I = 0; while (I <5) {System. out. println (I); I ++ ;}}}
2. If the condition is true, the execution is repeated at least once.
The difference with while is that, whether it is true or not, it is executed once before judgment.
Public class HelloWorld {public static void main (String [] args) {// print 0 to 4 // The difference with while is that, whether it is true or not, run it once first, then judge int I = 0; do {System. out. println (I); I ++;} while (I <5 );}}
3.
For Loop, same as while, but different expressions
Public class HelloWorld {public static void main (String [] args) {// use while to print 0 to 4 int I = 0; while (I <5) {System. out. println ("while loop output" + I); I ++;} // use for to print 0 to 4 for (int j = 0; j <5; j ++) {System. out. println ("for loop output" + j );}}}