嵌套的Else-Ifs不会超越第一个 - 如果 [英] Nested Else-Ifs Do Not Go Beyond The First Else-if

查看:65
本文介绍了嵌套的Else-Ifs不会超越第一个 - 如果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在这里有一个很棒的代码,它告诉你的年龄与生日前一天的生日那天相同(所以计算机就像没有?但是当涉及到时,我也会想到这一点年龄!)。但是,正如你所看到的,嵌套的else-ifs不会超越第一个if-if级别。我认为这应该工作,特别是当第一个嵌套的else-if工作时。 (Nutty C ++。)


必须求助于if(条件和条件)才能使其工作。


Now WeaknessForCats解释了为什么它不起作用,但那是在最后一个主题,这是一个不同的主题,我碰巧开始这一切。所以请在这里粘贴你的回复,然后我会回复。


虽然这里应该采取的一点是它不会这样工作,这就是全部应该重要。


谢谢

Now here is a wonderful code I made, that tells your age the same as was on your last birthday TILL one day before of your birthday (so computer-like no? but I too happen to think that way when it comes to age!). But, as you can see, the nested else-ifs don''t go beyond the first else-if level. And I think this SHOULD work, especially when the first nested else-if works. (Nutty C++.)

One has to resort to if (condition && condition) to make it work.

Now WeaknessForCats explained something about why it won''t work but that was in the last thread which was a different topic where I happened to start all this. So please paste your reply here, then I''ll respond.

Though the point that should be taken here is that it won''t work this way, and which is all that should matter.

Thanks

展开 | 选择 | Wrap | 行号

推荐答案

如果并且检查那个条件,它将不会转到下一个其他条件,因为它只选择条件为真的第一个条件。


只需移动代码第二个,如果进入第一个。
It''s not going to go to the next else if and check that condition because it only picks the first one where the condition is true.

Just move the code in the second else if into the first.


嗯然后,它不可能完成,因为那不是所需要的:第一个其他的第一个条件 - 如果今后不是每个集合都是共同的。
Well then, it can''t be done, since that is not what is required: the first condition of the first else-if is not common to the every set henceforth.


它可以是完成。第一个if if条件与第二个if条件完全相同。如果它具有不同的条件,它只是嵌套的。这没关系,它仍然有效。
It can be done. The first else if condition is exactly the same as the second else if condition. It is only the nested if that has differing conditions. And that''s fine, it will still work.


这篇关于嵌套的Else-Ifs不会超越第一个 - 如果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆