- 1
Can we only use 'break statement ' in infinite while loop or also in normal while loop
Can we use it in for loop
4 Réponses
+ 3
Purple Phoenix
You can use it in a normal while loop also.
+ 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
+ 2
If you use break inside infinite loop then it would not be infinite because break will stop execution of loop at some point.
+ 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