• #### 科普

SCIENCE

#### 英语

ENGLISH

#### 科技

TECHNOLOGY

MOVIE

FOOD

#### 励志

INSPIRATIONS

#### 社会

SOCIETY

TRAVEL

#### 动物

ANIMALS

KIDS

#### 卡通

CARTOON

#### 计算机

COMPUTER

#### 心理

PSYCHOLOGY

#### 教育

EDUCATION

#### 手工

HANDCRAFTS

#### 趣闻

MYSTERIES

CAREER

GEEKS

#### 时尚

FASHION

• 精品课
• 公开课
• 欢迎下载我们在各应用市场备受好评的APP

点击下载Android最新版本

点击下载iOS最新版本

扫码下载译学馆APP

#### 【用代数讲计算机科学】游戏中的组合判断

CS in Algebra: Big Game Compound Booleans

Sam the Bat is safe from leaving the left side of the screen or from leaving the right

side of the screen.

Let’s combine the safe-left and safe-right functions so that we can keep Sam safe from

leaving the left AND the right sides.

To do both, we’ll need to use compound Booleans.

We already know Boolean expressions can return true or false.

Well, we can combine multiple Boolean expressions together to create compound Booleans that

will also return true or false.

There are two functions we can use to combine Booleans: AND and OR.
AND函数需要两个布尔类型变量
The AND function takes in two Booleans and only returns true if BOTH of its Booleans

are true.

For example, if we asked, is this shape red? and is this shape a circle?

The answer would be true because both of the Booleans are true.

If we asked the same questions for this circle, the answer would be false because while one

of the Booleans is true, the other is false.

The other way to combine Booleans with OR which also takes in two Booleans but returns

true if at least ONE of the Booleans is true.

Let’s look at this shape for an example.

Is it a square or green?

Is it a star or a circle?

Is it a star or green?

The answer to each of these questions is true.

Use compound Booleans to keep Sam safe from leaving the left and the right sides of the

screen.

【B】Cod