Hi all,
I need to declare a variable that is only used in a do-while loop, and my question is where to best declare and initialise it. I have been reading that it is best to declare variables at the inner most scope, and therefore in the case of do loops it will be like this:
Because this is a loop, does this mean that "t" will be declared and initialised at every cycle?, or will it be declared and initialised only at the first cycle of the do loop?Code:do { double t = 0; /* variable declared and initialised inside the loop */ statements; } while (expression);
Obviously I could use this:
but I am just wondering about declaring/initialising variables inside loops.Code:double t = 0; /* variable declared and initialised outside the loop */ do { statements; } while (expression);
Thanks,
Spiros