当前位置:网站首页>Javescript loop
Javescript loop
2022-07-25 11:47:00 【c_ perfectworld】
loop
Purpose : Repeat some statements
JS The cycle in
for loop
while loop
do...while loop
for loop
The statement that is repeatedly executed is called the loop body , Can we continue , Depends on the of the loop Termination conditions , A statement consisting of the body of a loop and its termination conditions , be called Loop statement
Grammatical structure :

Initialize variable , Just use var A common variable declared , Usually used for timers
Conditional expressions are used to determine whether each cycle continues , Is the condition of termination
The operation expression is the code executed at the end of each loop , It is often used to update counter variables ( Increasing and decreasing )
Execution process :

Power off commissioning

double for loop
Print multiple lines and columns , It needs to be realized by loop nesting
A nested loop It refers to the structure of defining a circular statement in a circular statement , For example, in for In loop statement , You can nest another for loop , In this way for Circular statements we call double for loop
for Loop summary
- for A loop can repeat some of the same code
- for Loops can repeatedly execute different code , Because we have counters
- for Loops can repeat certain operations , For example, arithmetic operators and addition operations
- As demand increases , double for Can do more , Better to see
- double for loop , Outer circle once , Inner layer for The loop is fully executed
- for A cycle is a cycle in which cyclic conditions are directly related to numbers
while loop
while ( Conditional expression ) {
// The loop body
}Execution ideas : When the result of the conditional expression is true, be Execution loop body , otherwise Exit loop
do while loop
do {
// The loop body
} while ( Conditional expression )Execution ideas : Follow while The difference is this do while First execute the loop body to judge the condition If the conditional expression turns out to be true , Then continue to execute the loop body , Otherwise exit the loop
do while Loop at least once
Be careful : Execute the loop first , To determine , We will find that do...while The loop executes the loop code at least once
Loop summary
- js There is for while do while There are three kinds of cycles
- In many cases, the three cycles can be used instead of each other
If used for counting or numerical Correlation , The three are basically the same , But I prefer to use for
- while and do while You can make more complex judgment conditions , Than for More flexible
- while and do while The execution order is different ,while Judge before you execute ,do while Execute once before judgment
- while and do while Execution times are different ,do while At least once ,while Maybe not once
continue keyword
Used to immediately jump out of this loop , So let's go to the next loop
break keyword
Exit all loops
Identifier naming specification
- Variable function names must be meaningful
- Variable names are usually nouns
- Functions generally use verbs
边栏推荐
猜你喜欢

W5500在处于TCP_Server模式下,在交换机/路由器网络中无法ping通也无法通讯。

The most efficient note taking method in the world (change your old version of note taking method)

SQL language (4)

Reflection reflection

Small and micro enterprise smart business card management applet

SQL language (I)

Review in the middle of 2022 | understand the latest progress of pre training model

论文解读(MaskGAE)《MaskGAE: Masked Graph Modeling Meets Graph Autoencoders》

第4章线性方程组

【USB设备设计】--复合设备,双HID高速(64Byte 和 1024Byte)
随机推荐
SQL注入 Less23(过滤注释符)
Shell - Chapter 6 exercise
Hacker introductory tutorial (very detailed) from zero basic introduction to proficiency, it is enough to read this one.
Filter过滤器解决request请求参数乱码的原理解析
基于cornerstone.js的dicom医学影像查看浏览功能
Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
Convert string to number
Let sports happen naturally, and fire creates a new lifestyle
Oracle parsing XML with the same name
Brief description of model deployment
Introduction to shortcut keys in debug chapter
Dynamic planning question 05_ Missile interception
SQL language (6)
OneNET平台控制W5500开发板LED灯
Various controls ==pyqt5
JaveScript循环
[leetcode brush questions]
基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现
Summary of combination problems of Li Kou brush questions (backtracking)
SQL注入 Less18(头部注入+报错注入)