explain break vs continue statement like I'm 5

This is what I understand.
break totally exits the loop, no next iteration.
continue cancels anything below “continue” and goes to next iteration.
This confuses the hell out of me. Can you guide me in an easy way?

You have it right!

“Break” is like saying, “I’m done with this game, let’s go do something else.” When you use “break” in JavaScript, it means you want to stop doing the tasks or going through the line of toys. You can leave the game and do something different.

On the other hand, “continue” is like saying, “Okay, I’m done with this toy, let’s move on to the next one.” When you use “continue” in JavaScript, it means you want to skip the current task or toy and go directly to the next one. You don’t stop playing the game, but you move on to the next thing without finishing what you were doing before.

So, “break” means you want to stop and do something else entirely, while “continue” means you want to skip the current thing you are fiddling with move on to the next one in the same category of things you are doing.

1 Like

thanks @kirupa

1 Like