Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the pits in the Java loop

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report