Preface to learn in self
JavaThe process of language, it is easy to put
BreakAnd
ContinueConfusion of usage. In order to facilitate the quick review and study, in this special stay to learn a note.
A brief description of the body part of any iteration statement can be
BreakAnd
ContinueThe flow of control loops. which
BreakUsed to forcibly exit a loop without executing the remaining statements in the loop. and
ContinueStops executing the current iteration, then returns to the start of the loop and begins the next iteration. The code below this program to show you
BreakAnd
ContinueIn
forAnd
whileExamples in the loop:
Package Com.mufeng.thefourthchapter;public class Breakandcontinue {public static void main (string[] args) {for (int i = 0; I < 100; i++) {if (i = =) {//out of for Loopbreak;} if (i% 9! = 0) {//Next iterationcontinue;} System.out.print (i + "");} SYSTEM.OUT.PRINTLN (); int i = 0;while (true) {I++;int j = i * 27;if (j = = 1269) {//Out of Loopbreak;} if (i%! = 0) {//Top of Loopcontinue;} System.out.print (i + "");}}}
Output results
Source code parsing in this
forCycle,
IThe value will never reach
-, because once I arrives
About,
BreakThe loop is interrupted by the statement. In general, you need to use this only if you do not know when the interrupt condition is met
Break。 Just
ICannot be
9Divisible
ContinueStatement causes the execution process to return to the beginning of the loop (which causes the
Ivalue is incremented). If divisible, the value is displayed. The result of the output is displayed
0, is due to
0%9Equals
0。 Finally, you can see an "infinite
whileCycle "situation. However, inside the loop there is a
BreakStatement to abort the loop. In addition, you will also see
ContinueThe statement execution sequence moves back to the beginning of the loop without completing
ContinueThe content used after the statement. (Only in
ICan be
TenThe value is only printed when the integer is divisible. )
The difference between break and continue in Java (attached source)