• 科普

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: Booleans

How many numbers are there?

All of the types of data you’ve seen so far have infinite variations

which allows for a lot of variety in your programs.

But sometimes, you just need a simple yes or no, true or false.

There’s actually a type just for that.

A Boolean is a type of data that can only have one of two possible values: true or false.

That makes them really well-suited to answer simple true or false questions for our program,

such as 3 is less than 4 which we could speak as is 3 less than 4?

The value that returns is true since 3 is less than 4.

Booleans are useful for comparing things.

We can ask if one number is less than another

if two strings are equal and so on.

Mathematical functions like less than, greater than or equal

all take two numbers as their domain

and produce a Boolean as their range by comparing the two numbers.

Sometimes we want to compare values in more complex ways.

For example, asking if a player’s X coordinate is greater than 0 AND less than 100.

Or if string equals up OR down.

And even if a number is NOT 42.

These blocks (AND, OR, and NOT) allow us to modify and combine Booleans to answer more

interesting and logical questions.

In this stage, you’ll need to write Boolean functions to make sure sprites in a game follow

the rules that you set out for them, such as not going off the side of a screen.

【B】Cod