Skip to content
← Back to Community
How do you properly do a break function?
Profile icon
ChezTacoz

I typed in:
break()

This gave me a syntax error what did I do wrong?

Answered by bearbearmo [earned 5 cycles]
View Answer
Voters
Profile icon
LeandraBrutus
Profile icon
nazeww
Profile icon
ChezTacoz
Comments
hotnewtop
Profile icon
bearbearmo

what language is this in? and in what context are you using it?
in most languages break is used to break a loop

for(let i = 0; i < 10; i++){ if(i === 5) break; console.log(i); }

this outputs the numbers 0 to 4, because when I is 5 it breaks the loop.
the correct syntax is just break no (). I hope this is helpful

Profile icon
ChezTacoz

@bearbearmo
I'm using python

Profile icon
ChezTacoz

@bearbearmo
also thx

Profile icon
Axrevyn

@ChezTacoz
You should mark his answer as correct. Click the checkmark next to his answer, under the upvote counter.