Do-While loop


I have a workflow that downloads a csv file from a website. The time it completes the download is dependent on the amount of data. Some download faster than the others.

I created a do-while loop that checks for the file’s availability in the folder and the counter reaches 30, only then will it move to the next sequence.dowhile

If I change the condition to "fileExist = false or fileCtr = 30, it automatically moves to the next sequence, even if the file is not yet completely downloaded.

Can anyone help as I need the file to be completely downloaded/saved before it moves to the next?

Appreciate your help.

Hello Raymond,

You may want to consider trying to figure out a better way to download the file if this isn’t keeping your state suspended until moving on. There should be a way, either by checking the GUI that you are working with or using a different technique, to do so.

You’re essentially just counting to thirty ticks of your static delay and hoping that your file exists at the end. If you absolutely have to do it this way, then do not forget to check if your file exists once more outside of the loop and throw an error if it doesn’t.

Also, you should never do something like fileExist = True. Just do fileExist or Not fileExist because it is itself a boolean value.


What you want to achieve is that the DoWhile executes while the file doesn’t exist and the counter is less than 30 right? So your condition needs to be set like this: Not fileExists And fileCtr < 30.

This is because the conditions needs to indicates when to keep running, in your case, while both file doesn’t exists and your counter is lower than 30.

By the way, I’ll recommend you to use a timer with the loop instead of a counter with a delay. This is better because you won’t need to wait for the delay to finish to check if the file exists, as the loop will run, checking the condition at every time, without stopping until the ammount of time you want.

This is an snippet I created to reuse when I need a loop DoWhile with a timer and throwing an exeption if condition is not met: Loop with Timeout.xaml
If you like to use it and have any questions just let me now! :grinning:

It seems you posted a few seconds before I confirm mine :sweat_smile: sorry if it seems repeted!

1 Like

Thank you @dmccammond

@nerlichman, What I am in fact trying to do is for the sequence to validate the existence of the file OR wait til the counter reaches 30 before it exits the loop and use the downloaded/saved csv file for the next sequence.

The flow, however, treats the incomplete file as already existing, thus exiting out. In turn, the next sequence returns an error since the file still has yet to complete it’s saving.


use while loop inside it use Element Exists and mention the condition as mentioned below screen

A Manohar

Ok, try this: Not fileExist Or fileCtr < 30

This will continue the loop as long as the file doesn’t exist and the count is less than 30.
When the file check returns True, or the counter reaches 30, the loop will exit. I recommend you to check if the file exists after the loop and throw an exception if it doesn’t.