当前位置:网站首页>JS process control
JS process control
2022-07-25 11:47:00 【c_ perfectworld】
Process control
During program execution , various Code execution order Yes The result of the procedure It's influential , Many times we have to Control the execution order of the code Come on Realization What we want function
Simple understanding : Process control controls the structural order in which the code is executed
Process control has three structures , Sequential structure , Branching structure , Loop structure , The three structures represent three code execution sequences
Sequential structure
According to the code Order , Execute sequentially
Branching structure
During execution from top to bottom , according to Different conditions , perform Different path codes , obtain Different results
- if sentence
- switch sentence
if ( Conditional expression ) {
// Execute statement
}If if The result of the conditional expression is true , Execute... In braces , If if The conditional expression is false , Do not execute the , perform if Code after statement
if else sentence

if The words in it 1 and else The words in it 2 Finally, only one statement can execute
else Followed directly by braces
if else if ( Multi branch statement )
if ( Conditional expression 1) {
Execute statement 1
} else if ( Conditional expression 2) {
Execute statement 2
} else if ( Conditional expression 3) {
Execute statement 3
} else {
Last statement
}
Ternary expression
Yes Ternary operator The formula is a ternary expression
Conditional expression ? expression 1 : expression 2Execution ideas : If the conditional expression is true , Then return the expression 1 Value , If the conditional expression is false , Then return the expression 2 Value
switch sentence
It is also a multi branch statement , Used to execute different code based on different conditions , When you want to set a series of specific value options for variables , Use switch
switch ( expression ) {
case value1:
Execute statement 1;
break;
case value2:
Execute statement 2;
break;
...
default:
Last statement ;
}Execution ideas : Use the value of the expression and case The following option values match , If match up , It's time to do it case The words in it , If none of them match , execute default The words in it
Be careful :
- In development , Expressions are often written as variables
- num The value of and case When matching inside, it is congruent , The value must be consistent with the data type
- If at present case There's no break, Will not quit switch, Is to continue executing the code , Whether it can match or not
switch Statement and if else if The difference between
- General situation , Can replace each other
- switch case Usually dealing with case Compare the situation of certain value ,if else if More flexible , It is often used to judge the range
- switch Statement to directly execute the conditional statement of the program after judgment , More efficient ,if else There are several conditions , You have to judge how many times
- When there are fewer branches if else More efficient
- When there are many branches ,switch More efficient
边栏推荐
- SQL language (II)
- 擎创科技加入龙蜥社区,共建智能运维平台新生态
- Only know that the preform is used to generate objects? See how I use unity to generate UI prefabs
- 硬件外设=maixpy3
- 小区蔬菜配送的小程序
- [IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training
- Wiznet embedded Ethernet technology training open class (free!!!)
- 谣言检测文献阅读十一—Preventing rumor spread with deep learning
- W5500 multi node connection
- 任何时间,任何地点,超级侦探,认真办案!
猜你喜欢

leetcode 剑指 Offer 27. 二叉树的镜像
![[leetcode brush questions]](/img/86/5f33a48f2164452bc1e14581b92d69.png)
[leetcode brush questions]

leetcode 剑指 Offer 28. 对称的二叉树

【mysql学习08】

Teach you how to configure S2E as the working mode of TCP client through MCU

Common web attacks and defense

Introduction to shortcut keys in debug chapter

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

如何解决“W5500芯片在TCP_Client模式下,断电重启之后无法立即连接到服务器”的问题

Attendance system based on w5500
随机推荐
JS中的函数
Plot ==pyqt5
擎创科技加入龙蜥社区,共建智能运维平台新生态
基于W5500实现的考勤系统
Want to record your supernatural moments when playing games? Let's take a look at how to use unity screenshots
Getting started with redis
Understanding: idea uses Scala to write wordcount programs and generate jar packages
[electronic device notes 5] diode parameters and selection
flinksql client 连接kafka select * from table没有数据报错,如何解决?
JVM性能调优方法
How to judge the performance of static code quality analysis tools? These five factors must be considered
Let sports happen naturally, and fire creates a new lifestyle
Database integrity -- six constraints learning
Only know that the preform is used to generate objects? See how I use unity to generate UI prefabs
Reinforcement learning (IV)
Teach you how to configure S2E as the working mode of TCP server through MCU
SQL注入 Less23(过滤注释符)
Varest blueprint settings JSON
Some errors of tensorflow calling multiple GPUs
硬件外设=maixpy3