• Post Reply Bookmark Topic Watch Topic
  • New Topic

For Loop with multiple initializations  RSS feed

 
Sam Samson
Ranch Hand
Posts: 63
IntelliJ IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Could someone tell me where something like this is useful?



I mean, why not declare x outside the for loop? I've never seen a for loop like that so far.


greez
Sam
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose it would be useful wherever the loop in question had two indices to deal with that were not obviously related to each other. Maybe x increments and y decrements? Another characteristic is liable to be that x and y are not useful outside the loop; someone might put them inside the loop mechanism to emphasize to the reader that the variables are not used elsewhere, since they'd be out of scope.

Not one of your more pervasive constructs, to be sure...

rc
 
Campbell Ritchie
Marshal
Posts: 56586
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ralph Cook wrote: . . . Not one of your more pervasive constructs, to be sure...
Thank goodness!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!