Is there a way to skip for and while loops while debugging Python code in VS Code? I have to call a method that iterates through a 2D array before I get to where I actually want to debug, so it’s kind of annoying to have to do that each time I try to debug.
Question posted in Visual Studio Code
View the official documentation.
View the official documentation.
2
Answers
Set a breakpoint after the line that needs to be skipped. You can also edit breakpoints and enter expressions to skip them.
If supported by your extension’s debugger contribution, you could put your cursor at the line you want to "skip to", and then use the "run to cursor" item of the context menu. Python supports this. See also How to use the "jump to cursor" debugger command when debugging Python in Visual Studio Code.
If you have no breakpoints in the loop body that would interfere with this, you could also just put a breakpoint where you want to "skip to", and let execution break there. If you do have breakpoints in the loop body that would interfere with this, you could temporarily disable those breakpoints (see their context menu). Perhaps you might also find conditional breakpoints useful for that, but I doubt it (check out VSCode debugger conditional breakpoints).