How to use Trace function ?

Guys I have recently started to learn loops and facing problems in debugging. I have searched for debugging techniques and found the best one is use of trace function. I tried to understand but could not.
Please help me with this. It would be great i can get a small example of this too. Thanks a lot

See also:

Thanks for the reply. I have read this forum, but could not get enough details on how to use trace function?

What exact trouble are you facing?
Is it with the internal trace from log window or are you trying to use the external one?
You need to open the log window and use the Trace tab.

Are you familiar with C++ style Printf() formatting

If you are using _TRACEF() inside loops, you can access specific values at the iterating index like

// I is the iterating variable
_TRACEF("Close value at %g is %g", i, C[i]);

For non-loops eg.

// For Last value
_TRACEF("Close last value is %g", LastValue( C) );

// For selected value in chart bar
_TRACEF("Close selected value is %g", SelectedValue( C) );

Multi variable eg., you can add a few variables in test altogether.

_TRACEF("Last Close of %s is %g", Name(), LastValue( C) );