View Single Post
Old 11-27-2010, 02:31 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by corecase View Post
This is how i would do it:

Code:
int m = mark;
int d = daysLate;

if(m <= 20)
{
    System.out.println("Mark is: " + m);
}
else
{
    while(d >= 0 && m > 20)
    {
         m -= 5;
         d--;
    }
    System.out.println("Mark is: " + m);
}
I think it's a bit easier to understand than using a for loop with two variables inside. Just my opinion though! Hope it helps!
Your right, multiple variables and conditions in a for loop do tend to get complicated looking quite quickly, and neither approach has any additional overhead, so a simple if check followed by a while would be much easier to read than a single for loop.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote