What are the basic statements of javascript

藏色散人
Release: 2023-01-05 16:11:08
Original
4676 people have browsed it

The basic statements of JavaScript are: 1. if selection statement; 2. switch multi-condition selection statement; 3. for loop statement; 4. while loop statement; 5. do-while loop statement; 6. break and continue jump statement.

What are the basic statements of javascript

## The operating environment of this article: windows7 system, javascript version 1.8.5 , Dell G3 computer.

1. if selection statementConditional statements are used to perform different actions based on different conditions.
·if() statement - Use this statement to execute code only when the specified condition is true
Standard expression:
if(){ }
·if()…else statement - when Execute code when the condition is true, execute other code when the condition is false
Standard expressions: if( ){ }else{ }
·if()…else if()…else statement - use this statement to Select one of multiple code blocks to execute
Standard expressions: if( ){ }else if( ){ } else{ };
·The expression in the if statement () will be automatically converted into a Boolean value.

2. Switch multi-condition selection statementUse the switch statement to select one of multiple code blocks to be executed. (Mostly used for fixed value analysis and judgment, easy to expand)
Standard syntax:

What are the basic statements of javascript

·Working principle: First set the expression n (usually a variable).

·The value of the expression is then compared with the value of each case in the structure.
·If there is a match, the code block associated with the case will be executed.
·Please use break to prevent the code from automatically running to the next case.
·default keyword to specify what to do when the match does not exist:

3. for loop statementIn programming, some instructions need to be executed many times, so loop statements are used.
The syntax of for loop:

What are the basic statements of javascript

·Statement 1 is executed before the loop (code block) starts

·Statement 2 defines the conditions for running the loop (code block), if statement 2 If true is returned, the loop will start again, if false is returned, the loop will end.
·Statement 3 is executed after the loop (code block) has been executed
·Statement 1 is optional, which means that you can not use statement 1.
·If you omit statement 2, then a break must be provided within the loop. Otherwise the cycle cannot be stopped. This may crash the browser.
·Statement 3 is also optional.
Nesting of for statements:

What are the basic statements of javascript
What are the basic statements of javascript

4. While loopThe while loop tests a condition before execution. If Enter the loop when the condition is met.
The syntax of while loop:

What are the basic statements of javascript

##5. Do-while loop

The while loop tests a condition before execution, while the do-while loop first Execute the loop, and then test whether the condition is trueSyntax of do-while loop:

What are the basic statements of javascript##6. Break and continue jump statements

break will jump out directly and end the current loop structure.continue is used to skip an iteration in the loop.The continue statement can only be used in a loop; break can only be used in a loop or switch.


[Recommended learning: javascript advanced tutorial

]

The above is the detailed content of What are the basic statements of javascript. 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!