• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

For Loop with multiple initializations

 
Ranch Hand
Posts: 63
IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ralph Cook wrote: . . . Not one of your more pervasive constructs, to be sure...

Thank goodness!
 
reply
    Bookmark Topic Watch Topic
  • New Topic