bundyxc Posted August 11, 2009 Share Posted August 11, 2009 I need help condensing my conditionals. I have lots of elseifs, and I want to take them out. Should I put it into a single elseif, or should they remain seperate for the sake of maintainability? How would I put them into a single if/else? if (($i == 7) && ($j == && ($containsLimit != FALSE)) { echo '</tr></table><br /><br /><br />'; $i = 1; $j = 1; $k = 1; } //If that was a limitless train, and that was the last possible row, end the table. elseif (($containsLimit == FALSE) && ($k == $thisLimit)) { echo '</tr></table><br /><br /><br />'; $i = 1; $j = 1; $k = 1; } //If that was a limited train, and that was the last possible row, end the table. elseif (($containsLimit == TRUE) && ($k == $rowsLeft)) { echo '</tr></table><br /><br /><br />'; $i = 1; $j = 1; $k = 1; } //If that was the sixth column, and not the eighth row, end the row, and start a new one. elseif (($i == 7) && ($j != ) { echo '</tr><tr>'; $i = 1; $j++; $k++; } else { $i++; $k++; } Quote Link to comment Share on other sites More sharing options...
halfman Posted August 11, 2009 Share Posted August 11, 2009 why not using Switch ? Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 11, 2009 Share Posted August 11, 2009 A switch is only useful when you have a single parameter as the switch. I have a feeling there's a more logical way to approach your problem, but I can't see what you are actually doing. The first three conditions all have the same result. So there is no reason you have to separate them. This should accomplish the same thing //If that was a limitless train, and that was the last possible row, end the table. //OR If that was a limited train, and that was the last possible row, end the table. if ( (($i == 7) && ($j == && ($containsLimit != FALSE)) || (!$containsLimit && $k==$thisLimit) || ($containsLimit && $k==$rowsLeft) ) { echo '</tr></table><br /><br /><br />'; $i = 1; $j = 1; $k = 1; } //If that was the sixth column, and not the eighth row, end the row, and start a new one. elseif (($i == 7) && ($j != ) { echo '</tr><tr>'; $i = 1; $j++; $k++; } else { $i++; $k++; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.