visual studio debug jump out of loop

skeept picture skeept · Apr 22, 2013 · Viewed 13.1k times · Source

I know about basic features of visual studio debugging. F10, F11, Shift-F11, ctrl-F10.

If I am inside a for loop is there a way of stopping right after the loop is completed? Right now the way I am doing it is to manually go to the location after the loop and press ctrl-F10. Is there a better way of doing this?

Answer

Cody Gray picture Cody Gray · Apr 23, 2013

There is no dedicated "Step Out of Loop" command in Visual Studio. "Step Out" (Shift+F11) works only for functions. There are only two options that I can think of:

  1. Like Brian suggests, there is Run to Cursor, which has been there at least since VC++ 6. This is what you're already getting with the Ctrl+F10 keyboard shortcut. I use this literally all the time while debugging; it's an extremely useful tool. I don't really understand why you think this is a lousy way of doing it, or why you think there should be a "better" way.

  2. You could set a simple breakpoint on the line of code immediately following the loop. This is relatively simple if you use the keyboard shortcut F9. But you still have to navigate to the appropriate line of code, so you might as well use Run to Cursor.

If you're working in a C-derived language, your loops probably conclude with a }. So you could use the Ctrl+] keyboard shortcut to move to the matching brace in the source file if your caret is at the loop's opening brace. That might make navigation easier. It certainly can help avoid moving your hands over to the mouse, killing precious seconds.

* Note that keyboard combinations are subject to change, depending on how you have configured your Visual Studio environment.