- 1

Can we only use 'break statement ' in infinite while loop or also in normal while loop

Can we use it in for loop

14th May 2022, 7:14 AM
Purple Phoenix 7
Purple Phoenix 7 - avatar
4 Réponses
+ 3
Purple Phoenix You can use it in a normal while loop also.
14th May 2022, 7:19 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
A god way to fund it out is to test it in an example code: * write a while loop that runs while n is < 10 * start with n = 0, increase by 1 on each iteration, always print n * then put an if-statement in the loop: break if n > 5
14th May 2022, 7:24 AM
Lisa
Lisa - avatar
+ 2
If you use break inside infinite loop then it would not be infinite because break will stop execution of loop at some point.
14th May 2022, 8:56 AM
A͢J
A͢J - avatar
+ 2
break is only use inside loop or switch case. return can be used inside loop and outside loop also but it should be inside function. You cannot use return outside the function
14th May 2022, 8:58 AM
A͢J
A͢J - avatar