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

Time:10-24

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

CodePudding user response:

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}

CodePudding user response:

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.

CodePudding user response:

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).

  • Related