+ 4
What is the break keyword
7 Respostas
+ 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
+ 7
Greg My Pleasure !!! 😊
+ 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.
+ 1
tnx
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.
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
- 1
break is the keyword to terminate the switch statement