当前位置:网站首页>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
边栏推荐
- Use three.js to realize the cool cyberpunk style 3D digital earth large screen
- 任何时间,任何地点,超级侦探,认真办案!
- Filter过滤器解决request请求参数乱码的原理解析
- Flinksql client connection Kafka select * from table has no data error, how to solve it?
- 硬件外设=maixpy3
- 常见WEB攻击与防御
- 什么是全局事件总线?
- cookie and session
- Reinforcement learning (IV)
- [MySQL learning 08]
猜你喜欢

Reflection reflection

SQL language (I)

Common web attacks and defense

"Mqtt protocol explanation and Practice (access to onenet)" of wiznet w5500 series training activities

Information management system for typical works of urban sculpture (picture sharing system SSM)

JVM performance tuning methods
Details of the list of state products that Apple announced to be eligible for the sales tax holiday in the United States

Detailed explanation of zero basis from macro to micro Bert

Learn NLP with Transformer (Chapter 1)

圆角大杀器,使用滤镜构建圆角及波浪效果!
随机推荐
Detailed explanation of lvs-nat and lvs-dr modes of LVS load balancing
使用Three.js实现炫酷的赛博朋克风格3D数字地球大屏
[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training
How to judge the performance of static code quality analysis tools? These five factors must be considered
圆角大杀器,使用滤镜构建圆角及波浪效果!
ESP8266 使用 DRV8833驱动板驱动N20电机
flinksql client 连接kafka select * from table没有数据报错,如何解决?
Greedy problem 01_ Activity arrangement code analysis
Small and micro enterprise smart business card management applet
Reflection reflection
WIZnet W5500系列培训活动之“MQTT协议讲解和实践(接入OneNET)”
The first C language program (starting from Hello World)
Talking about Devops monitoring, how does the team choose monitoring tools?
第4章线性方程组
教你如何通过MCU配置S2E为TCP Server的工作模式
SQL注入 Less18(头部注入+报错注入)
JaveScript循环
Leetcode sword finger offer 28. symmetric binary tree
The principle analysis of filter to solve the request parameter garbled code
Review in the middle of 2022 | understand the latest progress of pre training model