Detailed explanation of javascript flow control statement Switch statement and for loop example code

伊谢尔伦
Release: 2017-07-24 09:42:56
Original
2438 people have browsed it

Multiple choices (Switch statement)

When there are many options, switch is more convenient to use than if else.


switch(表达式) { case值1: 执行代码块 1 break; case值2: 执行代码块 2 break; ... case值n: 执行代码块 n break; default: 与 case值1 、 case值2...case值n 不同时执行的代码 }
Copy after login

Syntax description:
Switch must be assigned an initial value, and the value matches each case value. Satisfies all statements after executing the case, and uses the break statement to prevent the next case from running. If all case values do not match, the statement after default is executed.
Example: Let’s make a weekly plan, learn concept knowledge on Monday and Tuesday, practice in the company on Wednesday and Thursday, summarize experience on Friday, rest and have fun on Saturday and Sunday.


Copy after login

for loop
Many things are not just done once, but done repeatedly. For example, print 10 copies of the test paper, one at a time, and repeat this action until the printing is completed. We use loop statements to accomplish these things. A loop statement is to repeatedly execute a piece of code.
for statement structure:


for(初始化变量;循环条件;循环迭代) { 循环语句 }
Copy after login

Example: If there are 6 balls in a box, we take one at a time and repeatedly take out the balls from the box until the ball While supplies last.


Copy after login

We have 1, 2, 3...10 money of different denominations. Use the for statement to complete the total and see how much money we have in total?


Copy after login

The above is the detailed content of Detailed explanation of javascript flow control statement Switch statement and for loop example code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!