----conditional loops in Java statements

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.