• Post Reply Bookmark Topic Watch Topic
  • New Topic

For loops - understanding variable values after each iteration  RSS feed

 
Natasha Reaney
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still get confused with understanding what values the variables in a for loop have taken on after one iteration. Here is an example:


I am confused by the xcurrent variable. Why is it necessary to include at the end of the loop body? I.e. does the xstart go back to its original value after one iteration? Or does it maintain the xstart value that it was given at the end of the loop body and carry that into the next iteration? I hope this makes sense.

Thank you!
Natasha
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no, the value will not be reset. The only time that a variable will be reset is if you explicitly do it yourself:



In the above, each time you come back through the loop, x will be reset, but only because I told it to do so.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!