Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-19-2011, 05:48 AM   PM User | #1
joey,choey
New Coder

 
Join Date: Jul 2008
Posts: 48
Thanks: 1
Thanked 0 Times in 0 Posts
joey,choey is an unknown quantity at this point
For loop incrementing pattern HELP

Hello there,
I have a really urgent need of assistance. I'm absolutely stuck on this...

Is there anyway to make a for-loop increment by 1 the first run, and then by 6 then next run, then 1, then 6, and so on.

ex: (increment 1, increment 6, increment 1, increment 6, ...)


Or if someone could point me in the right direction I'd really appreciate it.

Thank you much.

Last edited by joey,choey; 03-19-2011 at 05:51 AM..
joey,choey is offline   Reply With Quote
Old 03-19-2011, 08:35 PM   PM User | #2
Aradon
Moderator-san


 
Aradon's Avatar
 
Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Aradon is on a distinguished road
Sure this is possible, in a variety of ways.

Basically you'll need to use a boolean variable in order to turn on and off when you want to add by six and when you want to add by one.

So if you want to increment by six, just add five to your variable.

If you want to add by one, don't add anything.


Another alternative is to use the last parameter in the for loop to do the switching of the boolean variable.

In any case, hope that helps without actually doing the assignment for you!
__________________
"To iterate is human, to recurse divine." -L. Peter Deutsch
Aradon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:38 AM.


Advertisement
Log in to turn off these ads.