File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 726
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: 60049
    
  65

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: 39
    
    1
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: 726



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

Thanks again.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1939
    
  28
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: 726
Thanks from bottom of my heart
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1939
    
  28
My pleasure.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loop question
 
Similar Threads
is this sample code with good practice?
Q about polymorphism
Getting "not a multipart request" even though the image is being saved.
Confusion
Sending Webpage thru Java Mail