JavaScript Technology Lectures-Program composition

Source: Internet
Author: User
Tags format continue expression implement variable
Program

The basic composition of JavaScript scripting language is programmed by control statements, functions, objects, methods, attributes, etc.

One, program control flow

In any language, program control flow is necessary, it can make the whole program reduce chaos, so that it smoothly in a certain way to execute. The following are commonly used program control flow structures and statements for JavaScript:

1, if condition statement

Basic format

if (expression)

statement paragraph 1;

......

Else

statement paragraph 2;

.....

Function: If the expression is true, the statement segment 1 is executed, otherwise the statement segment 2 is executed.

Description

The If-else statement is the most basic control statement in JavaScript, which allows you to change the order in which statements are executed.

In an expression, you must use a relational statement to implement the judgment, which is evaluated as a Boolean value.

It converts 0 and nonzero numbers to false and true respectively.

If the statement after if has more than one line, you must enclose it with curly braces.

Nesting of IF statements

if (Boolean) statement 1;

Else (Boolean) statement 2;

else if (Boolean) statement 3;

......

Else Statement 4;

In this case, each level of the Boolean expression will be computed, if true, then execute its corresponding statement, otherwise execute else after the statement.

2, for Loop statement

Basic format

for (initialization; condition; increment)

Statement set;

Function: Implement conditional cycle, when the condition is set up, execute statement set, otherwise jump out of circulation body.

Description

The initialization parameter tells the starting position of the loop, and the initial value of the variable must be given;

Condition: is used to determine the condition of the circular stop. If the condition satisfies, then executes the circulation body, otherwise jumps out.

Increment: The primary definition of how the loop control variable changes in each loop.

Three main statements, you must separate them with commas.

3, while loop

Basic format

while (condition)

Statement set;

This statement, like the For statement, repeats the loop when the condition is true, or exits the loop.

For and while statements

Both statements are circular statements, and a for statement is easier to understand and compact when working with the numbers, while the while loop works more specifically for complex statements.

4. Break and Continue statements

As with the C + + language, use the break statement to make the loop jump out of a for or while, continue to skip the remaining statements in the loop and into the next loop.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.