karlstackoverflow
karlstackoverflow

Reputation: 3438

c# while loop to finish current loop before ending

I have a do while loop in my code and I am having it do about 30 lines of code each time within the loop. When it hits the while statement eg. it continues until ESC is pressed, Im not sure but will it complete the current loop or just up to the point where till the button is pressed? Because if all the code in the loop doesnt complete then the file it creates will be corrupted...

So does it complete the current loop, if not how can I make it so the while loop will allow it to complete before exiting?

Upvotes: 0

Views: 1574

Answers (2)

MattDavey
MattDavey

Reputation: 9027

If the check for the escape key is called within the While(...) block then yes, the loop will finish its current iteration before doing this check and deciding whether or not to loop again. If you're checking for the escape key inside the loop and calling break, then no, the iteration is not guaranteed to finish.

Upvotes: 0

Ankur
Ankur

Reputation: 33657

The code will exit where you have the condition check i.e while loop condition - while(somethingTrue), hence it will only break at the start of the while loop code block and not in between.

Upvotes: 1

Related Questions