in reply to Re^2: Printing largest number in array using loops and if statement
in thread Printing largest number in array using loops and if statement

But now your loop has one iteration too many as the first time into the loop the test necessarily fails.
One extra comparison vs one call to shift? That isn't anything I'd lose any sleep over.

Premature optimization is the root of all evil

  • Comment on Re^3: Printing largest number in array using loops and if statement

Replies are listed 'Best First'.
Re^4: Printing largest number in array using loops and if statement
by CountZero (Bishop) on Jan 17, 2010 at 07:48 UTC
    Of course, but as this is an exercise, it is good to think the whole algorithm through in all its consequences and see what effects even small changes in the code have on the logic of the algorithm. Otherwise you are only cargo-culting.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James