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