The Command.. break; in Java what if.?

后端 未结 8 503
走了就别回头了
走了就别回头了 2021-02-03 17:50

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

Example:

for (int i = 0; i < array.length; i++) {
           


        
相关标签:
8条回答
  • 2021-02-03 18:25

    The break command inside the IF statement will exit the FOR loop.

    0 讨论(0)
  • 2021-02-03 18:28

    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.

    See this section and this section of the Java tutorial.

    0 讨论(0)
提交回复
热议问题