0

If i have a loop (any loop)..lets say a for loop for now:

for(int x = 0; x < 100; x++)

if, within an iteration of the loop, i say:

x=50;

Will the next iteration of the loop jump to counter 50? Or does any change to the value of x within the loop not affect the loop counter?

xa.
  • 335
  • 2
  • 5
  • 13
  • Yes it will change the loop counter. Testing it is trivial and would probably have taken less time than writing the question ;) – jpw Oct 09 '14 at 01:23
  • Sotirios Delimanolis, that question is not helpful. The two questions are un-related. – xa. Oct 09 '14 at 01:24
  • You can reply with `@username` otherwise that user will not get notified. I think that one answers your question. If not, [this one must](http://stackoverflow.com/questions/20450056/how-does-a-for-loop-check-its-conditions-in-java?rq=1). If someone would be so kind as to reopen and reclose. – Sotirios Delimanolis Oct 09 '14 at 01:28
  • Are you still having trouble understanding the issue? – Sotirios Delimanolis Oct 09 '14 at 02:03

1 Answers1

-1

Rewrite the for loop below as a do-while loop.

for (int x=0; x<100; x++) 
cout << x << " "; 
int x=0; 
 do { 
 cout << x << " "; 
 x++; 
 } while (x<100);

Same for 50

John Stamoutsos
  • 353
  • 1
  • 3
  • 17