Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I have an angular foreach loop and i want to break from the loop if I match a value. The following code does not work.

angular.forEach([0,1,2], function(count){ 

if(count == 1){ 

break; 

});

How can I get this?

1 Answer

0 votes
by (106k points)

To break from the loop if you match a value you can use a boolean to just not going into the body of the loop. As follows:-

var keepGoing = true; 

angular.forEach([0,1,2], function(count){ 

if(keepGoing) { 

if(count == 1){ 

keepGoing = false; 

});

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...