if statement

Discussion in 'Mac Programming' started by larswik, Jun 28, 2011.

  1. larswik macrumors 68000

    Sep 8, 2006
    Is there a proper side in an IF statements expression to have the control value tested against another value (I hope I said that right).
        for (int i = 1; i <= 100; i++) {
            if (mostRolledNumber[i] < highestRollSoFar) {
                highestRollSoFar = mostRolledNumber[i];
    So should the 'mostRolledNumber' be to the right, left or it does not matter?

  2. balamw Moderator


    Staff Member

    Aug 16, 2005
    New England
    Depends what's in the parentheses.

    In this case (a>b) is very different from (b>a). :p

    In C the if just looks at the return value of the expression and checks if it is zero (a.k.a FALSE) or non-zero (a.k.a. TRUE).

    EDIT: Your code as posted will go through the array mostRolledNumber and update highestRollSoFar when it finds one LESS than highestRollSoFar, which may not be what you want since that tends to be a minimum finding routine.

  3. larswik thread starter macrumors 68000

    Sep 8, 2006
    Yep, I caught that the hard way :)



Share This Page