命令......休息;在Java中如果。? [英] The Command.. break; in Java what if.?

查看:112
本文介绍了命令......休息;在Java中如果。?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们在for循环中有if语句,它会停止循环或if条件...

What if we have an if statement inside a for loop, would it stop the loop or the if condition...

示例:

for (int i = 0; i < array.length; i++) {
    if (condition) {
        statement;
        break;
    }
}


推荐答案

break 语句对if语句没有影响。它仅适用于开关用于,而执行循环。所以在你的例子中,break将终止 for 循环。

The break statement has no effect on if statements. It only works on switch, for, while and do loops. So in your example the break would terminate the for loop.

参见本节本节

这篇关于命令......休息;在Java中如果。?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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