By default compiler does some optimizations, including one, which makes so variables allocated in CPU registers and not allocated in memory, which makes debugger unable to show you this variable. In case you are unable to debug some code, try moving Debug Complexity smart slider to Low position. This should ease debugging. To restore compiler options later, it is the easiest to copy and save whole compiler command line string. Just restore old settings string.
It is OK for compiler to ignore whole loops, provided result of loop execution is the same with optimization and without it. Execution time is not taken into account. Volatile variable of course disables such optimizations. Don't use for loops for timing delays, it is bad practice. Better use free running timer counter for short delays and periodic interrupt incremented variable for long delays. Say you have some counter variable (or timer counter register) running
volatile int cntr; // incremented by interrupt
// delay function.
// ticks has to be 0 <= ticks <= INT_MAX (defined in limits.h)
void WaitTicks(int ticks)
{
ticks += cntr;
while( (signed int)(cntr - ticks) < 0 )
{
}
}
You can't see function scope nonstatic variables updated in run mode. This is because they are allocated on stack, and stack pointer changes back and forwards when running, so debugger can't show such variables reliably in run mode.
The same problem is guaranted with variables, allocated in paged memory. Since page register changes at run time, debugger is not allowed to change page at run time, you won't be able to see such variables updated at run time.