GeeCON Prague 2014*
The moose likes Java in General and the fly likes Loop question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Loop question" Watch "Loop question" New topic
Author

Loop question

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Hello,

I want to reduce/refine the following code by merging if statement as I am repeating it 6 times.



Please advise

Best regards
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

As all those ifs do the same thing, it can be collapsed into a single conditional. But that's a lot of meaningless magic numbers. What do they mean?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sresh Rangi
Ranch Hand

Joined: Nov 28, 2012
Posts: 47
    
    2
All the conditions can be replaced with:


But it may be clearer with two nested loops: one to output the <tr>s and one to output the <td>s. That way there are no conditions required.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732



Great, but please can you explain this statement ( if i remainder 3 == 2 )

Thanks again.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2302
    
  49
Farakh khan wrote:
Great, but please can you explain this statement ( if i remainder 3 == 2 )

It is saying divide i by 3 and see if the remainder equals 2
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Thanks from bottom of my heart
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2302
    
  49
My pleasure.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loop question