« Home « Kết quả tìm kiếm

Controlling a Script's Flow


Tóm tắt Xem thử

- The buyStuff() function is called only if the variable moneySaved has a value greater than 500.
- If moneySaved is equal to or less than 500, the buyStuff() function call is ignored and actions immediately below the if statement are executed..
- The AND operator (&&) has been added to the statement so that now the buyStuff() function is called only if moneySaved is more than 500 and billsPaid has a value of true..
- The buyStuff() function is called if either moneySaved has a value greater than 500 or wonLottery has a value of true.
- In this script, the buyStuff() function is called only if moneySaved is more than 500 and billsPaid has a value of true, or if wonLottery has a value of true..
- The following table shows a list of the common operators (known as comparison operators because they're used to compare values) used in conditional logic, with brief descriptions and examples of how they're used..
- "Derek") name has an exact value of Derek.
- "Derek") name has a value other than Derek.
- Less than if (age <.
- 30) age has a value less than 30.
- Greater than if (age >.
- 30) age has a value greater than 30.
- <= Less than or equal to.
- if (age <= 30) age has a value less than or equal to 30.
- >= Greater than or equal to.
- if (age >= 30) age has a value greater than or equal to 30.
- day has a value of Friday and pmTime has a value greater than 5.
- day has a value of Saturday or Sunday.
- 300 does not assign a value of 300 to money.
- Rather, it asks whether money has a value of 300..
- Although number comparisons are straightforward—after all, most of us understand that 50 is less than 100—text-value comparisons are less obvious.
- Thus, if A has a value of 1, z has a value of 52.
- If/Else If Statements.
- if (money >.
- else if (money >.
- This script executes various actions depending on the value of money: "If money has a value greater than 500, buy the 35-inch TV.".
- If money has a value less than 500, this part of the script is ignored and the next condition is examined.
- The next condition says that if money has a value greater than 300, buy the 27-inch TV.
- Thus, if money has a value of 450 when this script is executed, the first part of the statement is ignored (because 450 is not greater than 500), but the second part of the statement is executed (because a value of 450 is greater than 300).
- If money has a value less than 300, both parts of this statement are ignored..
- If/Else Statements.
- Consider this the fail-safe part of the statement..
- In this script, if money doesn't have a value of at least 300, neither of the conditions analyzed is true.
- as a result, neither of the actions that follow the conditions will be executed.
- Instead, the actions following the else part of the statement are executed—it's a bit like saying this:.
- otherwise, if none of the conditions above is true.
- The statements we've discussed so far (and the syntax used) form the basis of most of the conditional logic you'll use in your projects.
- The value of the.
- If the condition within the parentheses evaluates to true, the first expression ("Happy") is set as the value of myMood.
- In this example, myMood will have a value of either "I'm happy".
- on whether the value of money is greater than or less than 1000000.

Xem thử không khả dụng, vui lòng xem tại trang nguồn
hoặc xem Tóm tắt