Java Fundamentals, Process Control statements

Source: Internet
Author: User

Process Control Statementsconditional statements: If statement: *if (Conditional Boolean type) {true}*if (Boolean expression) {true}else{false result}* Multiple if Else if () {}else if () {}else* nested IF switch statement:                      *switch (expression) {case:break; ... default:}expression = = constant, default can be omitted. Loop statement:           While statement: while (Boolean expression) {loop body} first judgment after executionDo While statement: do{loop body}while (judging condition) is executed once and then judgedFor Loop: for (Initialize: Condition: variable change) {looping operation}the structure of the loop body that contains the loop statement is called multiple loops, and three loop statements can be nested or nested within each other. In a double loop, the outer loop executes once, and the inner loop executes a circle. foreach:loop Jump statement:           *Break , refuse to execute the loop after this cycle, and jump out of the layer loop control body* Continue: After terminating the loop, the loop after the loop is resumed, and the loop control body does not jump out of the layer . * Common: Break and continue do not execute after break/continue of this loop Exercise 1;Public class Test { //The first 5 in the output 1-100 can be divisible by 3 of the numberPublic static void Main (string[] args) {int num=0;for (int i = 1; I <100; i++) {if (i%3==0) {num++;System.out.println (i); }if (num==5) {Break ; } } }}Exercise 2;Public class Test { //The first 5 in the output 1-100 can be divisible by 3 of the numberPublic static void Main (string[] args) {int num=0;for (int i = 1; I <100; i++) {if (i%3==0) {num++;System.out.println (i); }if (num==5) {Break ; } } }}

Java Fundamentals, Process Control 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.