An example of an infinite loop caused by a for statement in Java

For loop is often used in java development. It is very helpful to simplify business processing and improve efficiency. However, it is necessary to prevent the situation that may lead to dead cycles in the program algorithm, and some dead cycles are not easy to detect. For example, in the following example, the algorithm is very easy to think of as 50, which is actually an infinite loop.

Output results:

Conclusion: some people may think that the output result will be 50 times. In fact, it is an endless cycle. End is an infinite number, I < = end is an 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 approximation, and from start to end becomes an interval, which is 50. Therefore, the value range of various data types is considered in the development, especially when judging conditions and boundary values.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>