3

I'm trying to break a foreach if a bool variable is valorized:

 $.each(GlobalVariables.availableServices, function(index, service) 
 {
       if(state == true){  break;  }
       for (var k = 0; k < appointment.id_services.length; k++)
       {
             if(actual_option == appointment.id_services[k].id)
             {
                 serviceDuration = serviceDuration - parseInt(service['duration']);
                 state = true;
                 break;
              }
         }
 });

but I get this error:

Uncaught SyntaxError: Illegal break statement

on this line:

if(state == true){  break;  }

Why happean this?

Dillinger
  • 1,823
  • 4
  • 33
  • 78

0 Answers0