Random nested loop control cycle
Loop control
continue: terminate the current cycle -
Skip this cycle, we continue to the next cycle;
Use only continue in a loop out of the loop.
break: terminate the entire cycle -
Out of the loop, the end of the whole cycle;
In nested loops, break only terminate itself where a current layer (loop or switch), not all of the cycle terminates one time / switch; break may terminate switch, the cycle may be terminated;
If we infinite loop, there may be executed to terminate the loop, which is an infinite loop back can write code that does not report a syntax error.
The multilayer loop termination / Switch: return cycle can once ended;
System.exit (-1); the program ends.
java label:
Add a reference block can give them names, numbers located at the front statement corresponds to a statement declares the name.
lable:stastatement。
Usually a loop or switch
Nested loop
Outer executed once, the cycle lap. The circulation loop is external circulation.
Nested low efficiency, generally no more than three.
Random
Steps for usage:
Import package import java.util.Random;
Create Object Random r = new Random ();
Generating a random number int num = r.nextInt (10);
10 represents a range, generating a random number is 0-9; nextInt (n) will produce a greater than or equal to 0, an integer less than n.
the nextInt () generates a random number in the range of int, not recommended.
Generating a random number can be freely control the range
nextInt (n) + m: generating a random number range is: [m, m + n)
Direct nm nextInt (nm + 1) + m