Home > Web Front-end > JS Tutorial > body text

Summary of basic JavaScript knowledge (4) Conditional statements, loop statements

php中世界最好的语言
Release: 2018-03-10 11:54:23
Original
1376 people have browsed it

This time I will bring you a basic knowledge summary of JavaScript. There are a total of eleven knowledge points. Basic JavaScript knowledge summary (4) conditional statements and loop statements. Below are practical cases. Let’s take a look. one time.

Written at the front

OperatorAfter that, let’s talk about conditional statements and loop statements

Conditional statements

if

if else

Switch statement

Loop statement

for

while

do ....while

if(条件){    //条件为真时执行的方法}if(条件){    //条件为真时执行的方法}else{    //条件为假的时候执行的方法}if (条件 1)
  {
  当条件 1 为 true 时执行的代码
  }else if (条件 2)
  {
  当条件 2 为 true 时执行的代码
  }else
  {
  当条件 1 和 条件 2 都不为 true 时执行的代码
  }
for (语句 1; 语句 2; 语句 3)
  {  //被执行的代码块
  };for (var i=0;i<10;i++)
{document.write(i);
}
Copy after login
while(条件){    //需要执行的代码}var i;while(i<10){   document.write(i);
   i++;
}do
  {
  需要执行的代码
  }while (条件);do
  {  document.write(i);
  i++;
  }while (i<5);
switch(n)
{case 1:
  执行代码块 1
  break;case 2:
  执行代码块 2
  break;default:
  n 与 case 1 和 case 2 不同时执行的代码
}var n = "a";switch(n){    case "a":        console.log("a");        break;    case 2:        console.log("b");        break;    case true:        console.log("c");        break;    case 3:        console.log("d"); 
        break;
}//打印出来"a"、"b"、"c"、"d"//可以用break,来终止循环,只能写在循环里面;//continue,终止本次循环,进行下次循环
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

Summary of basic JavaScript knowledge (2) Introduction, variables, value types, operators

Summary of basic JavaScript knowledge (1)

##Summary of basic JavaScript knowledge (3) Comparison operators and logical operators

The above is the detailed content of Summary of basic JavaScript knowledge (4) Conditional statements, loop statements. 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
Popular Tutorials
More>
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!