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

How to realize flow Control in Java

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Java in how to achieve process control, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

# for loop

For (initialization statement; judgment condition statement; Control condition statement) {Loop body statement;}

Eg:

Public static void main (String [] args) {for (int I = 0; I)

< 100; i++){ System.out.println("第"+(i+1)+"循环"); } //for循环另外一种表达形式 int i = 0; for(;i < 10;i++){ System.out.println("当前i值:"+i); }} ####for-each循环 for(声明局部变量 :集合容器){ //需要执行的代码;} eg: public static void main(String[] args){ int[] items = {1,2,3,4,5,6,7,8,9,10}; for(int item:items){ System.out.println("元素是:"+ item); }} ####while循环 //只要布尔表达式结果为true,则会一直执行循环内容 while(布尔表达式){ //循环内容; } while循环的特点是先判断布尔表达式是否为真,如果为真,继续执行循环体,否则跳过循环 public static void main(String[] args){ int a = 10; while(a >

0) {a muri; System.out.println ("current a =" + a);}}

# do..while loop

The Boolean expression is after the body of the loop, so the statement block is executed before the Boolean expression is detected. If the Boolean expression evaluates to true, the statement block executes until the Boolean expression evaluates to false.

# Select structure

If...else condition judgment

Eg

# switch...case...default branch judgment

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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

Internet Technology

Wechat

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

12
Report