当前位置:网站首页>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); }}50502.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); } } ************ 13.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 25504. 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
边栏推荐
- 组播和广播的知识点梳理
- Zynq learning notes (3) - partial reconfiguration
- Vite configures the development environment and production environment
- Codeforces Round #804 (Div. 2)
- Review of double pointer problems
- Ad20 is set with through-hole direct connection copper sheet, and the bonding pad is cross connected
- Lepton 无损压缩原理及性能分析
- EditorUtility.SetDirty在Untiy中的作用以及应用
- Extension of graph theory
- MySQL time processing
猜你喜欢

程序员在互联网行业的地位 | 每日趣闻

ORM aggregate query and native database operation

Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example

Why does MySQL need two-phase commit

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

GAMES202-WebGL中shader的編譯和連接(了解向)

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

行业专网对比公网,优势在哪儿?能满足什么特定要求?

Fuzzy -- basic application method of AFL

Programmers' position in the Internet industry | daily anecdotes
随机推荐
Postman pre script - global variables and environment variables
Redis 排查大 key 的4種方法,優化必備
Compilation et connexion de shader dans games202 - webgl (comprendre la direction)
JS quick start (II)
[classic example] binary tree recursive structure classic topic collection @ binary tree
[buuctf.reverse] 159_ [watevrCTF 2019]Watshell
树莓派3.5寸屏幕白屏显示连接
Tetris
驱动开发——HelloWDM驱动
F12 solve the problem that web pages cannot be copied
Three.js学习-光照和阴影(了解向)
浅谈镜头滤镜的类型及作用
What are the advantages of the industry private network over the public network? What specific requirements can be met?
[noip2008 improvement group] stupid monkey
[leetcode daily question] number of enclaves
Project manager, can you draw prototypes? Does the project manager need to do product design?
Hometown 20 years later (primary school exercises)
Postman manage test cases
CUDA11.1在线安装
Idea one key guide package