不带括号的嵌套 if 语句

发布于 2024-09-29 20:26:30 字数 254 浏览 1 评论 0原文

给出以下代码:

       if (c2-c1==0)
        if ( c1 != c3 )
                    {...}

如何解释此代码?第一个 if 语句没有{}。上面的代码是否等于下面的代码?:

 if (c2-c1==0){
    if ( c1 != c3 )
                {...}
 }

following code is given:

       if (c2-c1==0)
        if ( c1 != c3 )
                    {...}

How do I interpret this code? The first if-statement comes without {}. Is the code above equal to the following code?:

 if (c2-c1==0){
    if ( c1 != c3 )
                {...}
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

少跟Wǒ拽 2024-10-06 20:26:30

是的。 if 语句适用于它之后的下一个语句 - 在本例中,它恰好是另一个 if 语句。

Yes. The if statement applies to the next statement after it - which happens to be another if in this case.

指尖上的星空 2024-10-06 20:26:30

是的,它们是等价的

Yes, they are equivalent

み零 2024-10-06 20:26:30

绝对地。不加括号意味着第一个 if 中的唯一指令是另一个 if,它可以包含您想要的任何内容。

Absolutely. Putting no brackets means that the only instruction in the first if is the other if, which can contains anything you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文