Does the break statement break out of loops or only out of if statements?

前端 未结 9 1615
孤街浪徒
孤街浪徒 2020-12-16 15:12

In the following code, does the break statement break out of the if statement only or out of the for loop too?

I need it to b

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 15:57

    It would break you out of the for loop. Generally break statement is used to optimise the running time of your program. Means when the given condition is met, use break statement so that it will take you out of the loop and ignores the remaining iterations.

提交回复
热议问题