ADM-201 dump PMP dumps pdf SSCP exam materials CBAP exam sample questions

【用代数讲计算机科学】条件语句 – 译学馆
未登陆,请登陆后再发表信息
最新评论 (0)
播放视频

【用代数讲计算机科学】条件语句

CS in Algebra: Conditionals

布尔类型可以让我们在程序中提问 例如 这个值是年龄
Booleans allow us to start asking questions in our programs such as, is the value of age
大于15吗? 或者 名字是John吗?
greater than 15? or does name equal John?
这可以让我们引入逻辑来让程序变得更智能
This lets us start introducing logic into our programs but to make them really smart,
我们想要程序有能力作出基于布尔类型问题的答案的决定
we want our programs to be able to make decisions based on the answers to Boolean questions.
条件语句可以让我们实现这种方式
Conditionals let us do exactly that.
一个条件语句让你编写一系列布尔类型的问题和它们相关的代码
A conditional lets you program a list of Boolean questions and their associated code.
你列表中条件语句开始于问题或者条件或者检查
The conditional starts at the top of your list of questions or conditions and checks
问题的对错
whether that question is true or false.
如果条件为真, 那么将执行相关的代码进行求值
If the condition is true, then the associated code is evaluated as a result.
如果条件为假, 那么将会忽略相关代码并且继续下一条
If the condition is false, the associated code is ignored and we move on to the next
在列表中的条件语句
condition in the list.
这有一个简单的条件语句来检查年龄变量并且返回一个
Here’s a simple conditional to check the variable age and return a string describing someone
描述符合条件年龄的字符串
of that age.
让我们看一下当我们对年龄设为15时会发生什么
Let’s see what happens when we evaluate with this age set to 15.
年龄等于三呢?
What about when age is 3?
现在, 如果年龄为50时会发生什么
Now, what should happen if age is 50?
我们没有一个条件符合50
None of our conditions evaluated true for 50.
这有点麻烦
That’s a bit troublesome.
如果没有一个条件为真, 我们可以提供一个else语句
If none of the conditions are true, we can provide a catch-all value called the else
接收所有的值
statement.
else语句只在所有条件为假时执行
The else statement only runs if none of the other conditions are true.
所以 通过在最后添加一个成人描述, 我们可以接收所有超出
So by adding adult to the end of our conditional, we can catch ages outside of the range of
我们现存条件的值
our existing conditions.
你条件语句的先后顺序时非常重要的
The order in which you place your conditions is very important.
返回真的第一个条件就是符合条件的那一个
The first condition that returns true is the one that wins.
让我们看一下如果我们把我们的年龄检查语句顺序颠倒会发生什么
Let’s look what happens if we put our age-checking conditionals in the reverse order.
你期望当年龄设为15时会发生什么
What would you expect it to return with age set to 15?
3 或者50呢?
How about 3? or 50?
下一阶段, 你将会编写条件语句来作出逻辑决定
In the next stage, you’ll write programs that use conditionals to make logical decisions.
每一个条件语句至少需要一个条件和一个else语句
Every conditional needs to have at least one condition and an else statement.
如果你需要检查更多的条件, 点击放在else语句上的添加按钮
If you need to check against more conditions, click the plus button above the else statement.
如果你想减少条件, 点击你想删除的条件旁边的minus按钮
If you want fewer conditions, click the minus button next to the condition you wish to remove.

发表评论

译制信息
视频概述
听录译者

收集自网络

翻译译者

【B】Cod

审核员

自动通过审核

视频来源

https://www.youtube.com/watch?v=zloUEeHfvlI

相关推荐