当前位置:网站首页>JaveScript循环
JaveScript循环
2022-07-25 10:54:00 【c_perfectworld】
循环
目的:重复执行某些语句
JS中的循环
for循环
while循环
do...while循环
for循环
被重复执行的语句称为循环体,能否继续执行,取决于循环的终止条件,由循环体及循环的终止条件组成的语句,称之为循环语句
语法结构:

初始化变量,就是用var声明的一个普通的变量,通常用于计时器使用
条件表达式用来决定每一次循环是否继续,就是终止的条件
操作表达式是每次循环最后执行的代码,经常用于计数器变量进行更新(递增和递减)
执行过程:

断电调试

双重for循环
打印多行多列的内容,需要通过循环嵌套来实现
循环嵌套是指在一个循环语句中再定义一个循环语句的结构,例如在for循环语句中,可以再嵌套一个for循环,这样的for循环语句我们称之为双重for循环
for循环小结
- for循环可以重复执行某些相同的代码
- for循环可以重复执行不同的代码,因为我们有计数器
- for循环可以重复执行某些操作,比如算数运算符加法操作
- 随着需求增加,双重for可以做更多,更好看的效果
- 双重for循环,外层循环一次,内层for循环全部执行
- for循环是循环条件和数字直接相关的循环
while循环
while (条件表达式) {
//循环体
}执行思路:当条件表达式结果为true,则执行循环体,否则退出循环
do while循环
do {
//循环体
} while (条件表达式)执行思路:跟while不同的地方在于 do while 先执行一次循环体在判断条件 如果条件表达式结果为真,则继续执行循环体,否则退出循环
do while 循环至少执行一次
注意: 先执行循环体,再判断,我们会发现do...while循环至少执行一次循环代码
循环小结
- js中有 for while do while循环三种
- 三种循环很多情况下可以相互替代使用
如果用来计数或者数字相关的,三者使用基本相同,但是更喜欢用for
- while和do while可以做更复杂的判断条件,比for更灵活
- while和do while执行顺序不一样,while先判断后执行,do while先执行一次后判断
- while 和do while执行次数不一样,do while至少执行一次,while可能一次也不执行
continue关键字
用于立即跳出本次循环,继续下一次循环
break关键字
退出所有循环
标识符命名规范
- 变量函数命名必须有意义
- 变量名称一般用名词
- 函数一般用动词
边栏推荐
- 基于MATLAB的常见线性调制方法
- Reflection reflection
- SQL注入 Less17(报错注入+子查询)
- Teach you how to configure S2E as the working mode of TCP server through MCU
- SQL注入 Less18(头部注入+报错注入)
- 小微企业智能名片管理小程序
- The most efficient note taking method in the world (change your old version of note taking method)
- Reinforcement learning (IV)
- Database design - Simplified dictionary table [easy to understand]
- Layout management ==pyqt5
猜你喜欢

黑客入门教程(非常详细)从零基础入门到精通,看完这一篇就够了。

小区蔬菜配送的小程序

Introduction to shortcut keys in debug chapter

How to judge the performance of static code quality analysis tools? These five factors must be considered
![[MySQL learning 09]](/img/27/2578f320789ed32552d6f69f14a151.png)
[MySQL learning 09]

工作面试总遇秒杀?看了京东T8大咖私藏的秒杀系统笔记,已献出膝盖

Leetcode sword finger offer 28. symmetric binary tree

SQL injection less23 (filter comment)

Only know that the preform is used to generate objects? See how I use unity to generate UI prefabs

Information management system for typical works of urban sculpture (picture sharing system SSM)
随机推荐
The principle analysis of filter to solve the request parameter garbled code
Database design - Simplified dictionary table [easy to understand]
基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现
小微企业智能名片管理小程序
Let sports happen naturally, and fire creates a new lifestyle
Esp8266 uses drv8833 drive board to drive N20 motor
Talking about Devops monitoring, how does the team choose monitoring tools?
W5500在处于TCP_Server模式下,在交换机/路由器网络中无法ping通也无法通讯。
Shell fourth day homework
DICOM medical image viewing and browsing function based on cornerstone.js
Oracle parsing XML with the same name
菜单栏+状态栏+工具栏==PYQT5
Shell - Chapter 6 exercise
varest蓝图设置json
黑客入门教程(非常详细)从零基础入门到精通,看完这一篇就够了。
硬件外设=maixpy3
The most efficient note taking method in the world (change your old version of note taking method)
Dynamic planning problem 03_ Maximum sub segment sum
将字符串转换为数字
【leetcode刷题】