Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by FunkyMonk (Chancellor)
on Jan 17, 2010 at 00:09 UTC ( [id://817803]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://817803]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 02:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found