How to exit for each loop?

I have a number of files in a folder & using a for loop to read each file one by one. How do I come out of the for loop after all the files are read?
In my case the loop is reading again all the files from the beginning after completing one round.

1 Like

@sayanghosh333 For Each ends its loop after the Iteration ends or the Collection has reached it’s last item. What have you given as a Collection?Can you provide a Screenshot?


Hi, this is the loop that I have.

@sayanghosh333 What is Out_FilePath?

  1. If you want to come of loop once the required file is found , Use Break Activity
  2. If you want all the files in folder to loop, You dont need to do anything. The loop will end once all the files are read from the folder.

Hi @sayanghosh333,
Use the ‘Break’ Activity,
In side the ‘If’ Activity (Give your Condition to Break the Loop),
Inside the ‘For Each
Like Below,

Cheers :beers:


Usually the expression you have used to get the filepath will contain some number of filepaths in it say 50

If that variable is passed to FOR EACH activity then it will iterate only for that 50 files not more than that or not less than that
Unless we add a IF condition and a BREAK activity it won’t stop in the middle either

So after completing the first round that is first loop it will take the second element in the loop that is second filepath

As the variable name is filepath inside the for each loop, make sure that the same variable is used inside the loop

Cheers @sayanghosh333

1 Like

Hi All,

If in case error will throw in first looping element…then for each will continuously execute looping or will it go to exception?

Can anyone help me with the answers.

if an exception occurs the playback stops, so yes, also your loop stops.
Unless… you make use of a try-catch error handler. Us it within the body of the loop and 1 exception will allow continuation of your workflow with the next item.