The for -loop is commonly used in Java development. It is very helpful for simplifying business processing, improving efficiency, and very helpful. However, it is necessary to prevent the situation of the dead cycle in the program algorithm, and some dead cycles are not well detected. For example, the following example is very easy to consider 50, which is actually an infinitely dead cycle.
Public Class CyCTEST { /** * @param ARGS The Command Line Arguments * /Public Static Void Main (String [] ARGS) {int End = Integer.Max_value; // Define a cycle The termination number can be infinitely large, different from int type. int Start = END-50; // Define the starting start value int count = 0; // initial value for (int i = start; i <= end; i ++) {// cycling body ++; .println ("The number of cycles is:"+Count); // Output}}}
Output results:
Run: The number of cycles in this cycle is: 1 The number of cycles this time is: 2 This cycle is: 3 ... The number of this cycle is: 49 The number of this cycle is: 50 This cycle is: 51 is 51 ... ...
Summarize:
Some people may think that the output result will be 50 times, which is actually a dead cycle. END is an infinite number, and i <= end is the infinite number. So there is no limit. For (Int I = Start, I <End; I ++), the result is 50. I <END means that the boundary value cannot be an infinite rough, and from Start to END, it has become a section, and the interval is 50. Therefore, in the development, the value range of various data types is taken into account, especially when the conditional judgment and boundary value.