Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Increment / decrement > 1 in a for () struct

 
Donald R. Cossitt
buckaroo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not been able to find information on how (if possible) to 'step' through a for() struct by increments other than one? Is this possible? Without doing math in the signature?
TIA
doco
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this possible?
Certainly.
Without doing math in the signature?
Well, without doing anything particularly complex. I mean the standard "i++" is a form of math. You can replace it with other statements though, such as:

or

or

The last in particular is probably a bad idea for readability, since it's not immediately obvious what j and k are, or how many times this loop will execute. But it's legal if you want to do something like that...
 
Donald R. Cossitt
buckaroo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now why didn't think of that?
Thanks
doco
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic