What are the pits in the Java loop
This article mainly introduces the relevant knowledge of "what are the pits in the Java cycle". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "what are the pits in the Java cycle" can help you solve the problem.
I. several grammars of circular statements
Syntax:
For Loop format: for (initialization statement; conditional judgment; Progressive statement) {Loop body;} while Loop format: initialization statement; while (conditional judgment) {Loop body; Progressive statement;} do-while Loop format: initialization statement; do {Loop body; Progressive statement;} while (conditional judgment)
Example:
Package org.pdool.wrongfor; import java.util.ArrayList;import java.util.List; / * circular format * @ author parsley * / public class Format {public static void main (String [] args) {List numList = new ArrayList (); numList.add (1); numList.add (2); / / for format System.out.println ("= for format ="); int size = numList.size () For (int I = 0; I < size; iTunes +) {int num = numList.get (I); System.out.print (num);} System.out.println (); / / enhanced for System.out.println ("= enhanced for format ="); for (Integer num: numList) {System.out.print (num) } System.out.println (); / / while System.out.println ("= while format ="); int I = 0; while (I < size) {int num = numList.get (I); System.out.print (num); iTunes;} / / do while System.out.println () System.out.println ("= do while format ="); int j = 0; do {int num = numList.get (j); System.out.print (num); jackers;} while (j < size);}} II. Points to pay attention to in the loop
As a server development, we need to pay attention to the performance of the server in the development. after all, there are tens of millions of clients and only one server, so it is necessary to squeeze the performance of the server. As a server developer, you should also be able to save a little bit. Sum up the attention points of the cycle.
1. If the loop meets the search requirements, break directly jumps out, do not waste performance
Public static void main (String [] args) {int size = 1000; for (int I = 1position I)