(iii) Process Statements
3. Control cycle Structure
1) break
* In the switch statement, use to terminate a sequence of statements.
* For exiting a loop, use the break statement to rush through the exit loop, ignoring any other statements and loop condition tests in the loop body.
* When a break statement is encountered in a loop, the loop is terminated and program control is restarted in the statement following the Loop.
Instance:
packageday4;Importjava.util.Scanner; public classexam_1 { public Static voidmain (string[] Args) {//TODO auto-generated Method StubScanner input =NewScanner (system.in); intnum = 1; intcut; System.out.println ("enter a number of 1-100"); Cut=Input.nextint (); while(num<=100) {System.out.println (num); if(num==Cut) { break; } num++; } }}
2) continue
* Discard subsequent non-executed program code in this Cycle.
Instance:
Using the If method:
With continue
3) return
* the return in the loop is used in cases where the loop Body contains a switch statement.
The code that encounters return in the loop and terminates at return will not Execute.
Where to terminate the loop, use return.
My Learning Record-java SE