如果动作/其他语法问题语法、动作、问题

2023-09-08 11:47:49 作者:一时失言乱红尘疼

以下哪个最好翻译英文语句如果是下雨,我们会看电影。否则,我们将去公园。

Which of the following best translates the English statement "If it's rainy, we will watch a movie. Otherwise we will go to the park."

   a. if (rainy = true) { gotoAndStop ("movie"); }
   b. if (rainy == true) { gotoAndStop ("movie"); }
   c. if (rainy = true) { gotoAndStop ("movie"); } else { gotoAndStop ("park"); }
   d. if (rainy == true) { gotoAndStop ("movie"); } else { gotoAndStop ("park"); }

我的答案是D - 是正确的。

My answer would be "d" - is that correct?

推荐答案

是的,D是正确答案。

和之间 = 的区别 == == 进行比较,并返回一个布尔值(true或false),你在(所谓的分支)运营。

The difference between = and == is that == compares and returns a Boolean (true or false) which you operate upon (called 'branching').

= 被称为赋值运算符,虽然完全有效的code写的,是不是你通常需要在if语句中使用。

= is called the assignment operator and while perfectly valid code to write, is not what you normally want to use in an if statement.

if(x = 5) {
    doStuff();
}

基本上意味着5而不是x的;如果x非零电话doStuff

Basically means "put 5 instead of x; if x is non-zero call doStuff".

另外需要注意的是,当涉及到布尔值,它是更安全写

Another thing to note is when it comes to booleans, it's "safer" to write

if (rainy) {
    gotoAndStop("movie");
} else {
    gotoAndStop("park);
}