Hướng dẫn selection statement in javascript - tuyên bố lựa chọn trong javascript

Trình bày về chủ đề: "JavaScript: Câu lệnh điều khiển I" - Bảng điểm trình bày:

1 JavaScript: Câu lệnh kiểm soát IJavaScript: Control Statements IJavaScript: Control Statements I JavaScript: Control Statements I

Nội dung chính ShowShow

  • Trình bày về chủ đề: "JavaScript: Câu lệnh điều khiển I" - Bảng điểm trình bày:
  • Cấu trúc điều khiển trong JavaScript là gì?
  • 4 cấu trúc điều khiển là gì?
  • 3 loại cấu trúc điều khiển với các ví dụ là gì?
  • Cấu trúc kiểm soát giải thích chi tiết là gì?

Nội dung chính ShowShowShow

  • Trình bày về chủ đề: "JavaScript: Câu lệnh điều khiển I" - Bảng điểm trình bày:
  • Cấu trúc điều khiển trong JavaScript là gì?
  • 4 cấu trúc điều khiển là gì?
  • 3 loại cấu trúc điều khiển với các ví dụ là gì?
  • Cấu trúc kiểm soát giải thích chi tiết là gì?

Nội dung chính ShowShow Introduction JavaScript provides three types of selection structures.
The if selection (single-selection statement) statement performs (selects) an action if a condition is true or skips the action if the condition is false. The if…else (double-selection statement) selection statement performs an action if a condition is true and performs a different action if the condition is false. The switch (multiple-selection statement) selection statement performs one of many different actions, depending on the value of an expression. JavaScript provides four repetition statements—while, do…while, for and for…in.

3

Cấu trúc điều khiển trong JavaScript là gì? if Selection Statement
A selection statement is used to choose among alternative courses of action in a script. For example: The preceding pseudocode If statement can be written in JavaScript as

2 Giới thiệu JavaScript cung cấp ba loại cấu trúc lựa chọn. Câu lệnh IF SELLE (Tuyên bố lựa chọn đơn) Thực hiện (chọn) một hành động nếu một điều kiện là đúng hoặc bỏ qua hành động nếu điều kiện là sai. ) Câu lệnh Lựa chọn thực hiện một hành động nếu một điều kiện là đúng và thực hiện một hành động khác nếu điều kiện là sai. Công tắc (câu lệnh đa hướng) Câu lệnh thực hiện một trong nhiều hành động khác nhau, tùy thuộc vào giá trị của biểu thức.JavaScript cung cấp bốn Các tuyên bố lặp lại trong khi, trong khi, làm trong khi, cho và cho các trò chơi trong.Introduction JavaScript provides three types of selection structures.The if selection (single-selection statement) statement performs (selects) an action if a condition is true or skips the action if the condition is false.The if…else (double-selection statement) selection statement performs an action if a condition is true and performs a different action if the condition is false.The switch (multiple-selection statement) selection statement performs one of many different actions, depending on the value of an expression.JavaScript provides four repetition statements—while, do…while, for and for…in.Introduction JavaScript provides three types of selection structures.The if selection (single-selection statement) statement performs (selects) an action if a condition is true or skips the action if the condition is false.The if…else (double-selection statement) selection statement performs an action if a condition is true and performs a different action if the condition is false.The switch (multiple-selection statement) selection statement performs one of many different actions, depending on the value of an expression.JavaScript provides four repetition statements—while, do…while, for and for…in. if…else Selection Statement
The if…else selection statement allows you to specify that a different action is to be performed when the condition is true than when the condition is false. For example: The preceding pseudocode If…Else statement may be written in JavaScript as

4 Nếu Tuyên bố lựa chọn Tuyên bố lựa chọn được sử dụng để chọn trong số các khóa học hành động thay thế trong một kịch bản. Ví dụ: mã giả trước đó nếu câu lệnh có thể được viết bằng JavaScript ASif Selection StatementA selection statement is used to choose among alternative courses of action in a script. For example:The preceding pseudocode If statement can be written in JavaScript asif Selection StatementA selection statement is used to choose among alternative courses of action in a script. For example:The preceding pseudocode If statement can be written in JavaScript as Conditional Operator (?:)
The operator ?: is JavaScript’s only ternary operator—it takes three operands. The operands together with the ?: form a conditional expression. The first operand is a boolean expression, the second is the value for the conditional expression if the expression evaluates to true and the third is the value for the conditional expression if the expression evaluates to false.

7 lồng nhau nếu ... các câu lệnh khác nếu các câu lệnh khác kiểm tra cho nhiều trường hợp bằng cách đặt nếu các câu lệnh khác bên trong nếu các câu lệnh khác.Nested if...else StatementsNested if…else statements test for multiple cases by placing if…else statements inside if…else statements.Nested if...else StatementsNested if…else statements test for multiple cases by placing if…else statements inside if…else statements. Nested if...else Statements
Nested if…else statements test for multiple cases by placing if…else statements inside if…else statements.

8 Vấn đề lủng lẳng-đòi hỏi sau đây minh họa vấn đề lơ lửng. Ví dụ: trình thông dịch diễn giải câu lệnh trước đó buộc câu lệnh nested đầu tiên phải thực thi vì dự định ban đầu, chúng ta phải viết nó như sau: niềng răng phần thân của câu lệnh IF đầu tiên và cái khác được khớp với câu lệnh IF đầu tiên.Dangling-else ProblemThe following code illustrates the dangling-else problem. For example,The interpreter interprets the preceding statement asTo force the first nested if statement to execute as it was intended originally, we must write it as follows:The braces ({}) indicate to the JavaScript interpreter that the second if statement is in the body of the first if statement and that the else is matched with the first if statement.Dangling-else ProblemThe following code illustrates the dangling-else problem. For example,The interpreter interprets the preceding statement asTo force the first nested if statement to execute as it was intended originally, we must write it as follows:The braces ({}) indicate to the JavaScript interpreter that the second if statement is in the body of the first if statement and that the else is matched with the first if statement. Dangling-else Problem
The following code illustrates the dangling-else problem. For example, The interpreter interprets the preceding statement as To force the first nested if statement to execute as it was intended originally, we must write it as follows: The braces ({}) indicate to the JavaScript interpreter that the second if statement is in the body of the first if statement and that the else is matched with the first if statement.

9 Trong khi cấu trúc lặp lại của Statementa Repetition (còn được gọi là vòng lặp) cho phép bạn chỉ định rằng tập lệnh là lặp lại một hành động trong khi một số điều kiện vẫn đúng. Câu lệnh như sau:while Repetition StatementA repetition structure (also known as a loop) allows you to specify that a script is to repeat an action while some condition remains true.The statement is as follows:while Repetition StatementA repetition structure (also known as a loop) allows you to specify that a script is to repeat an action while some condition remains true.The statement is as follows: while Repetition Statement
A repetition structure (also known as a loop) allows you to specify that a script is to repeat an action while some condition remains true. The statement is as follows:

10 Toán tử gán JOTAssignment OperatorsJavaScript provides several additional assignment operators (called compound assignment operators) for abbreviating assignment expressions.ExamplesAny statement of the form where operator is one of the binary operators +, -, *, / or %Assignment OperatorsJavaScript provides several additional assignment operators (called compound assignment operators) for abbreviating assignment expressions.ExamplesAny statement of the form where operator is one of the binary operators +, -, *, / or % Assignment Operators JavaScript provides several additional assignment operators (called compound assignment operators) for abbreviating assignment expressions. Examples Any statement of the form where operator is one of the binary operators +, -, *, / or %

11 toán tử tăng và giảmIncrement and Decrement OperatorsIncrement and Decrement Operators Increment and Decrement Operators

12

13 Thuật toán xây dựng: RepetitionConsider kiểm soát đối phó Tuyên bố vấn đề sau:Formulating Algorithms: Counter-Controlled RepetitionConsider the following problem statement:Formulating Algorithms: Counter-Controlled RepetitionConsider the following problem statement: Formulating Algorithms: Counter-Controlled Repetition
Consider the following problem statement:

14

15 Các thuật toán xây dựng: RepetitionConsider kiểm soát Sentinel Vấn đề sau: Phát triển tập lệnh trung bình lớp sẽ xử lý số lượng điểm tùy ý mỗi khi tập lệnh được chạy.Formulating Algorithms: Sentinel-Controlled RepetitionConsider the following problem:Develop a class-averaging script that will process an arbitrary number of grades each time the script is run.Formulating Algorithms: Sentinel-Controlled RepetitionConsider the following problem:Develop a class-averaging script that will process an arbitrary number of grades each time the script is run. Formulating Algorithms: Sentinel-Controlled Repetition
Consider the following problem: Develop a class-averaging script that will process an arbitrary number of grades each time the script is run.

16

17 câu lệnh kiểm soát lồng nhauNested Control StatementsNested Control Statements Nested Control Statements

18

19

20 yếu tố cần thiết của sự lặp lại được kiểm soát phản hồi được kiểm soát theo yêu cầu: Tên của biến điều khiển (hoặc bộ đếm vòng lặp). Giá trị ban đầu của biến điều khiển. Tăng (hoặc giảm) theo đó biến điều khiển được sửa đổi mỗi lần (còn được gọi là mỗi lần lặp của vòng lặp). Điều kiện kiểm tra giá trị cuối cùng của biến điều khiển để xác định vòng lặp nên tiếp tục.Essentials of Counter-Controlled RepetitionCounter-controlled repetition requires:The name of a control variable (or loop counter).The initial value of the control variable.The increment (or decrement) by which the control variable is modified each time through the loop (also known as each iteration of the loop).The condition that tests for the final value of the control variable to determine looping should continue.Essentials of Counter-Controlled RepetitionCounter-controlled repetition requires:The name of a control variable (or loop counter).The initial value of the control variable.The increment (or decrement) by which the control variable is modified each time through the loop (also known as each iteration of the loop).The condition that tests for the final value of the control variable to determine looping should continue. Essentials of Counter-Controlled Repetition
Counter-controlled repetition requires: The name of a control variable (or loop counter). The initial value of the control variable. The increment (or decrement) by which the control variable is modified each time through the loop (also known as each iteration of the loop). The condition that tests for the final value of the control variable to determine looping should continue.

21 cho tuyên bố lặp lạifor Repetition Statementfor Repetition Statement for Repetition Statement

22 Định dạng chung của một tuyên bốGeneral Format of a for StatementGeneral Format of a for Statement General Format of a for Statement

23 Số nguyên tổng hợp với một tuyên bốSumming Integers with a for StatementSumming Integers with a for Statement Summing Integers with a for Statement

24 Tính lãi kép với for for statementconsider Tuyên bố vấn đề sau:Calculating Compound Interest with the for StatementConsider the following problem statement:Calculating Compound Interest with the for StatementConsider the following problem statement: Calculating Compound Interest with the for Statement
Consider the following problem statement:

25

26 Chuyển đổi tuyên bố nhiều lựa chọnswitch Multiple-Selection Statementswitch Multiple-Selection Statement switch Multiple-Selection Statement

27

28 Chúng tôi tạo các danh sách khác nhau này bằng cách sử dụng kiểu danh sách thuộc tính CSS, cho phép chúng tôi đặt hệ thống đánh số cho danh sách. Các giá trị có thể La Mã (chữ số La Mã chữ hoa), alpha thấp hơn (chữ thường), trên alpha (chữ hoa), v.v.We create these different lists using the CSS property list-style-type, which allows us to set the numbering system for the list.Possible values include decimal (numbers—the default), lower-roman (lowercase Roman numerals), upper-roman (uppercase Roman numerals), lower-alpha (lowercase letters), upper-alpha (uppercase letters), and more.We create these different lists using the CSS property list-style-type, which allows us to set the numbering system for the list.Possible values include decimal (numbers—the default), lower-roman (lowercase Roman numerals), upper-roman (uppercase Roman numerals), lower-alpha (lowercase letters), upper-alpha (uppercase letters), and more. We create these different lists using the CSS property list-style-type, which allows us to set the numbering system for the list. Possible values include decimal (numbers—the default), lower-roman (lowercase Roman numerals), upper-roman (uppercase Roman numerals), lower-alpha (lowercase letters), upper-alpha (uppercase letters), and more.

29 Làm trong khi câu lệnh lặp lại trong khi câu lệnh, thử nghiệm tiếp tục vòng lặp xảy ra khi bắt đầu vòng lặp, trước khi phần thân của vòng lặp thực thi. Cơ thể vòng lặp luôn thực hiện ít nhất một lần.do…while Repetition StatementIn the while statement, the loop-continuation test occurs at the beginning of the loop, before the body of the loop executes.The do…while statement tests the loop-continuation condition after the loop body executes—therefore, the loop body always executes at least once.do…while Repetition StatementIn the while statement, the loop-continuation test occurs at the beginning of the loop, before the body of the loop executes.The do…while statement tests the loop-continuation condition after the loop body executes—therefore, the loop body always executes at least once. do…while Repetition Statement
In the while statement, the loop-continuation test occurs at the beginning of the loop, before the body of the loop executes. The do…while statement tests the loop-continuation condition after the loop body executes—therefore, the loop body always executes at least once.

30

31 Break và tiếp tục Tuyên bố Tuyên bố Breakthe Break Statement, khi được thực thi trong một thời gian, vì, thực hiện trong khi hoặc câu lệnh chuyển đổi, gây ra thoát ngay lập tức khỏi câu lệnh.break and continue Statementsbreak StatementThe break statement, when executed in a while, for, do…while or switch statement, causes immediate exit from the statement.Execution continues with the first statement after the structure.break and continue Statementsbreak StatementThe break statement, when executed in a while, for, do…while or switch statement, causes immediate exit from the statement.Execution continues with the first statement after the structure. break and continue Statements
break Statement The break statement, when executed in a while, for, do…while or switch statement, causes immediate exit from the statement. Execution continues with the first statement after the structure.

32 Tiếp tục tuyên bố Tuyên bố tiếp tục, khi được thực thi trong một thời gian, vì hoặc thực hiện trong khi tuyên bố, bỏ qua các câu lệnh còn lại trong phần thân của câu lệnh và tiến hành lần lặp tiếp theo của vòng lặp. Kiểm tra tiếp tục đánh giá ngay sau khi câu lệnh tiếp tục thực thi. Trong các câu lệnh, biểu thức gia tăng thực thi, sau đó thử nghiệm tiếp tục vòng lặp đánh giá. Vị trí tiếp tục tiếp tục trước khi tăng trong một thời gian có thể dẫn đến một vòng lặp vô hạn.continue StatementThe continue statement, when executed in a while, for or do…while statement, skips the remaining statements in the body of the statement and proceeds with the next iteration of the loop.In while and do…while statements, the loop-continuation test evaluates immediately after the continue statement executes.In for statements, the increment expression executes, then the loop- continuation test evaluates.Improper placement of continue before the increment in a while may result in an infinite loop.continue StatementThe continue statement, when executed in a while, for or do…while statement, skips the remaining statements in the body of the statement and proceeds with the next iteration of the loop.In while and do…while statements, the loop-continuation test evaluates immediately after the continue statement executes.In for statements, the increment expression executes, then the loop- continuation test evaluates.Improper placement of continue before the increment in a while may result in an infinite loop. continue Statement The continue statement, when executed in a while, for or do…while statement, skips the remaining statements in the body of the statement and proceeds with the next iteration of the loop. In while and do…while statements, the loop-continuation test evaluates immediately after the continue statement executes. In for statements, the increment expression executes, then the loop- continuation test evaluates. Improper placement of continue before the increment in a while may result in an infinite loop.

33 Toán tử logicJavaScript cung cấp các toán tử logic có thể được sử dụng để hình thành các điều kiện phức tạp hơn bằng cách kết hợp các điều kiện đơn giản. Các toán tử logic là && (logic và), || (logic hoặc) và! (logic không, còn được gọi là phủ định logic). && ((logic và) toán tửLogical OperatorsJavaScript provides logical operators that can be used to form more complex conditions by combining simple conditions.The logical operators are && (logical AND), || (logical OR) and ! (logical NOT, also called logical negation).&& (Logical AND) OperatorLogical OperatorsJavaScript provides logical operators that can be used to form more complex conditions by combining simple conditions.The logical operators are && (logical AND), || (logical OR) and ! (logical NOT, also called logical negation).&& (Logical AND) Operator Logical Operators JavaScript provides logical operators that can be used to form more complex conditions by combining simple conditions. The logical operators are && (logical AND), || (logical OR) and ! (logical NOT, also called logical negation). && (Logical AND) Operator

34 || (Logic hoặc) toán tử! (Phủ định logic) Nhà điều hành|| (Logical OR) Operator! (Logical Negation) Operator|| (Logical OR) Operator! (Logical Negation) Operator || (Logical OR) Operator
! (Logical Negation) Operator

Cấu trúc điều khiển trong JavaScript là gì?

Các cấu trúc điều khiển trong JavaScript cho phép luồng chương trình thay đổi trong một đơn vị mã hoặc hàm. Các câu lệnh này có thể xác định liệu các câu lệnh được đưa ra có được thực thi hay không - và cung cấp cơ sở cho việc thực thi lặp lại một khối mã.allow the program flow to change within a unit of code or function. These statements can determine whether or not given statements are executed - and provide the basis for the repeated execution of a block of code.allow the program flow to change within a unit of code or function. These statements can determine whether or not given statements are executed - and provide the basis for the repeated execution of a block of code.allow the program flow to change within a unit of code or function. These statements can determine whether or not given statements are executed - and provide the basis for the repeated execution of a block of code.

4 cấu trúc điều khiển là gì?

IF-OLSE điều kiện, câu lệnh trường hợp, cho các vòng lặp và trong khi các vòng lặp đều là cấu trúc điều khiển. are all control structures. are all control structures. are all control structures.

3 loại cấu trúc điều khiển với các ví dụ là gì?

Lưu lượng kiểm soát thông qua bất kỳ chức năng nào được thực hiện với ba loại cấu trúc điều khiển cơ bản:....

Tuần tự: Chế độ mặc định.....

Lựa chọn: Được sử dụng cho các quyết định, phân nhánh - lựa chọn giữa 2 đường dẫn khác.....

Lặp lại: Được sử dụng để lặp, tức là lặp lại một đoạn mã nhiều lần liên tiếp ..

Cấu trúc kiểm soát giải thích chi tiết là gì?

Một cấu trúc điều khiển giống như một khối lập trình phân tích các biến và chọn một hướng để đi dựa trên các tham số đã cho.Thuật ngữ điều khiển luồng chi tiết hướng mà chương trình thực hiện (theo cách điều khiển chương trình "luồng").Do đó, đây là quá trình ra quyết định cơ bản trong điện toán;Đó là một dự đoán.a block of programming that analyses variables and chooses a direction in which to go based on given parameters. The term flow control details the direction the program takes (which way program control "flows"). Hence it is the basic decision-making process in computing; It is a prediction.a block of programming that analyses variables and chooses a direction in which to go based on given parameters. The term flow control details the direction the program takes (which way program control "flows"). Hence it is the basic decision-making process in computing; It is a prediction.a block of programming that analyses variables and chooses a direction in which to go based on given parameters. The term flow control details the direction the program takes (which way program control "flows"). Hence it is the basic decision-making process in computing; It is a prediction.