• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loop question

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sresh Rangi
Ranch Hand
Posts: 54
5
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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

Thanks again.
 
Tony Docherty
Bartender
Posts: 2991
59
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks from bottom of my heart
 
Tony Docherty
Bartender
Posts: 2991
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic