当前位置:网站首页>Knowledge points of circular structure
Knowledge points of circular structure
2022-07-06 05:06:00 【I have nothing to do and like to chase plays】
1.while loop
while It's a basic cycle , Its cycle structure is :
while( Boolean expression ){ // Cycle content }
As long as the Boolean expression is true, The loop goes on and on
A small number of cases require a loop to be executed all the time , For example, the server's request response monitoring and so on .
The cycle condition is always true It's going to create a dead cycle , Our normal business should avoid dead circulation , It will affect the performance of the program or cause the program to jam and crash !.
Most of the time we stop the cycle , We need a way to invalidate the expression to end the loop .
Case study :
public class WhileDemo01 { public static void main(String[] args) { // Calculation 1+2+3+....+100 int i=0; int sum=0; while(i<=100){ sum=sum+i; i++; } System.out.println(sum); }}5050
2.do......while loop
do..while And whie be similar , The difference is do..while At least once .
while Judge before you execute ,do...while Execute before judge .
Case study ;
public class DoWhileDemo01 { public static void main(String[] args) { int a=0; while(a<0){ a++; System.out.println(a); } System.out.println("************"); do{ a++; System.out.println(a); }while(a<0); } } ************ 1
3.for loop
Make the cycle simpler .
It is a general structure that supports iteration , It is the most effective and flexible structure
grammar :
for( initialization ; Boolean expression ; to update ){ // Code statements }
// Calculation 0-100 The sum of odd and even numbers public class ForDemo02 { public static void main(String[] args) { int oddsum=0; int evensum=0; for(int i=0;i<=100;i++){ if(i%2==0){// even numbers evensum+=i; }else{ oddsum+=i; } } System.out.println(" The sum of odd numbers is "+oddsum); System.out.println(" The sum of even numbers is "+evensum); } } The sum of odd numbers is 2500 The sum of even numbers is 2550
4. stay java5 An enhancement mainly used for arrays is introduced in for loop
grammar :
for( Statement statement : expression ){ // Code sentence }
expression : Is the name of the array to access , Or the return value is an array .
Statement statement : Declare new local variables , The type of the variable must match the type of the array element , Its scope is limited to circular chunks , Its value is equal to the value of the array at this time .
Case study ;
public class ForDemo05 {public static void main(String[] args) { int [] numbers={10,20,30,40,50};// Define an array for(int x:numbers){ System.out.println(x); }}}1020304050
边栏推荐
- 图论的扩展
- Collection + interview questions
- 集合详解之 Collection + 面试题
- Microblogging hot search stock selection strategy
- EditorUtility.SetDirty在Untiy中的作用以及应用
- Orm-f & Q object
- What should the project manager do if there is something wrong with team collaboration?
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Postman test report
- Compilation et connexion de shader dans games202 - webgl (comprendre la direction)
猜你喜欢
Postman管理测试用例
ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
Excel转换为Lua的配置文件
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
What are the advantages of the industry private network over the public network? What specific requirements can be met?
Modbus协议通信异常
麦斯克电子IPO被终止:曾拟募资8亿 河南资产是股东
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
SQL injection vulnerability (MSSQL injection)
Fiddler installed the certificate, or prompted that the certificate is invalid
随机推荐
ISP学习(2)
Request (request object) and response (response object)
Redis 排查大 key 的4种方法,优化必备
2021RoboCom机器人开发者大赛(初赛)
[leetcode daily question] number of enclaves
Rce code and Command Execution Vulnerability
[classic example] binary tree recursive structure classic topic collection @ binary tree
Fiddler installed the certificate, or prompted that the certificate is invalid
Postman manage test cases
EditorUtility. The role and application of setdirty in untiy
Acwing week 58
[NOIP2009 普及组] 分数线划定
The underlying structure of five data types in redis
图论的扩展
關於Unity Inspector上的一些常用技巧,一般用於編輯器擴展或者其他
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
ORM aggregate query and native database operation
Collection + interview questions
ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder