DAY06 conditional loops in the Java language
First, the Condition Cycle Overview:
The condition loop is not unfamiliar to us at all, the use of circular statements in the program is a very general matter, so you must learn to loop the statement.
Second, the condition cycle
The conditional loop consists of two loop statements, namely If...else and Switch...case statements.
1. If Loop structure
if () {}else{}
2. Switch...case Cycle Structure
Switch () {case 1:break; Case 2:break; Case 3:break; Default:break;}
Third, examples:
package www.dzx.c1;import java.util.scanner;//programming Loop structure. Public class coustructs {public static void main (String[] args) {/*if ... else structure * if (condition) {} else { }*/int a = 45;if (a>30) {system.out.println ("Middle-aged! ");}  ELSE {SYSTEM.OUT.PRINTLN ("Youth! ");} ---------------------------------------------------/*switch structure * * switch (key) {case value:break;default:break;} *///use the input to implement a game console System.out.println ("Number 1th starts the game! "); System.out.println ("2nd view Help!) "); System.out.println ("Number 3rd exit the game!") "); System.out.println ("Please enter your choice!") The//scanner class is a class that accepts input Scanner sc = new scanner (system.in);int b = Sc.nextint ();//define a variable to accept the user's input! switch (b) {case 1:system.out.println ("Start the game! "); Break;case 2:system.out.println (" See Help!) Break;case 3:system.out.println ("Exit Game"); Break;default:system.out.println ("Your operation is invalid!) Please re-enter "), Break;}}
Iv. Concluding remarks:
We're done here. Conditional loop statements, which are very trivial to use, such as the use of this statement to determine when implementing login.
This article from "Lonely One Night" blog, reproduced please contact the author!
----conditional loops in Java statements