This is a short guide on how to use the debugger in Visual Studio Code (VSCode). The debugger allows you to stop the execution of your program at a breakpoint you choose, and then go through the code line-by-line to investigate the behavior of your program in detail. This is very beneficial for locating bugs (errors).

1. Add breakpoint: F9 (not on empty line)
2. Start: F5
3. Steps:

1. Into: F11 (go into functions)
2. Over: F10 (go over functions)
3. Out: Shift+F11 (continue until current function is finished)
4. Continue: F5 (to next breakpoint)

5. Stop: Shift+F5

Tutorial:

1. Write the following code

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19   def f(a,b): a += 2 b += 2 g(a,b) def g(a,b): a += 1 b += 1 a = 0 b = 0 f(a,b) f(a,b) f(a,b) f(a,b) f(a,b) print(a,b) 
2. Add breakpoint on line 11

3. Start debugger

4. Experiment with stepping into, over and out

5. Notice that the “Variables” window show the current values of all variables

6. Open the debug console with Ctrl+Shift+Y

7. Try writing e.g. a+2

Bonus info:

1. It also stops at errors.
2. Breakpoints can be made conditional (right click on it in list or by line number)