skip to Main Content

How to change initial iterator value of my loop to debug in VScode?

Example: I want debug my code starting i=10. How do I do to select this argument to my debugging? I’m loosing so many time clicking in "Step Over" to investigate my code. I’m using language C

Image VSCode

3

Answers


  1. You can do so by either taking the user input –> i (that’s inefficient) or else you can change i while debugging in vs code

    Here is a image for reference
    Image for reference in VS Code

    But incase you only want to check when i is k(some constant) without skipping the iterations below it(when i<k), you can use if(i>=k){code}

    Login or Signup to reply.
  2. Another option is a conditional breakpoint. Its condition can be when i has a specific value.

    enter image description here

    enter image description here

    enter image description here

    The big advantage is: you don’t need to recompile your code.

    Login or Signup to reply.
  3. The universal quick & dirty solution no matter debugger is to modify the code. For example:

    if(i==0)
    {
      volatile int x = 0; // set breakpoint here
    }
    

    It’s also good practice to surround such "debug only" code with a so-called "compiler switch": #ifdef DEBUG_MODE ... #endif. So that you don’t forget to remove the code and it makes it to release build by accident (very common problem).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search