作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一段 C 代码,我想了解程序中的第一个 else 是如何解释它后面的 if 的。通常在if-else连词中,当if中的条件为假时,程序执行else后面的语句,而else没有大括号。下面, else 之后没有大括号,所以我的问题是: else 是否解释“if(prefer>=5) { printf("Buya");printf("也许事情很快就会变得更好!\n");}"作为单个语句,类似于“else printf(“这是上述 else 的替换语句”);”施工?
或者 if - else if 连词还有另一种逻辑?例如,else 仅激活“if(prefer>=5)”,并且该条件如果为真,则执行大括号中的内容?
完整的C语言代码如下。预先感谢您。
#include <stdio.h>
int main()
{
int prefer=2;
if (prefer >= 8)
{
printf("Great for you!\n");
printf("Things are going well for you!\n");
}
else if(prefer>=5)
{
printf("Buya");
printf("Maybe things will get even better soon!\n");
}
else if(prefer>=3)
{
printf("Bogus");
printf("Maybe things will get worst soon!\n");
}
else
{
printf("Hang in there--things have to improve, right?\n");
printf("Always darkest before the dawn.\n");
}
return 0;
}
最佳答案
这里有一个更多括号的版本可以解释这一点:
if(prefer >= 8)
{
...
}
else
{
if(prefer >= 5)
{
...
}
else
{
if(prefer >= 3)
{
...
}
else
{
...
}
}
}
else if(condition) ...
没什么特别的。它相当于 else { if(condition) ... }
。
关于c - else 如何解释其后面的 if 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58782032/
我在 StackOverflow 和其他地方看到了很多与此类似的问题,但没有一个直接解决我的问题。我正在 THREE.js 中使用凸包生成器生成 n 边多面体。我想将方形纹理映射到每个多面体的每个面上
我是一名优秀的程序员,十分优秀!