How can i break my foreach loop ?
Question

I have two foreach loops . one inside other and after getting my match in if condition inside my javascript I want to break both foreach loop . how can i achieve this ?

Hi Pratik,

Using if condition you can break your loop. If you are using foreach loop in client action then based on if condition you can end it.

If you want to break loop in Javascript code then please refer below blog -

https://www.geeksforgeeks.org/how-to-break-nested-for-loop-using-javascript/

Thanks

Vinod

mvp_badge
MVP

Hi Pratik,

You can follow any of the below-mentioned pattern

1) If you don't have any additional operation after the outer loop execution then I would suggest this pattern.

2) If you do have any operation to be executed after the outer loop execution then follow the below-mentioned pattern.

i.e. Define MaxIteration (Integer data type) local variable for both inner and outer loop. Don't forget to assign the Local variables i.e. TemplateMaxIteration & FeatureMaxIteration, before the Outer loop node. When the condition inside the inner loop get satisfied set both TemplateMaxIteration & FeatureMaxIteration variable values to 0.

I hope this helps you!


Kind regards,

Benjith Sam

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.