What is the break keyword | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What is the break keyword

8th Jun 2018, 6:21 PM
Greg
Greg - avatar
7 Answers
+ 9
Greg break is used to exit out of the loops and move to the very next statement after loop for eg - for(i=0;i<5;i++) {if(i==2) break; else {other statements} } when i becomes 2 it gets out of the loop without looping for i values
8th Jun 2018, 6:27 PM
Mohammad Amir Aqeel
Mohammad Amir Aqeel - avatar
+ 7
Greg My Pleasure !!! 😊
8th Jun 2018, 7:26 PM
Mohammad Amir Aqeel
Mohammad Amir Aqeel - avatar
+ 2
break; keywords are used to control the flow of loop execution. when the compiler reaches the break; statement in any loops, it will terminates the loop and compiler jumps out of the corresponding loop and executes the remaining statements.
12th Jun 2018, 5:07 AM
LIVE STREAM TECHNOLOGIES
LIVE STREAM TECHNOLOGIES - avatar
+ 1
tnx
8th Jun 2018, 6:35 PM
Greg
Greg - avatar
0
break keyword is always used to break the flow of control of execution at the case where the required condition is being satisfied after execution of that case, so that execution of further cases should get avoided.
16th Jun 2018, 1:02 PM
Nikhil Gadakh
0
I made an easy code in javascript to see if a number is a prime number or not (there are probably better codes for this).. If you erase the « break » it is not gonna work, you can try it ! It’s going to tell you that 54 is a prime number ! https://code.sololearn.com/WYIDBhTDSGAk/?ref=app
22nd Aug 2018, 7:22 PM
Elsa Lubek
- 1
break is the keyword to terminate the switch statement
13th Jun 2018, 2:45 PM
Awoyemi Hafeez
Awoyemi Hafeez - avatar