in reply to Re: Printing largest number in array using loops and if statement
in thread Printing largest number in array using loops and if statement
start with $big = $array[0] insteadYou spotted the logical error!. Well done.
But now your loop has one iteration too many as the first time into the loop the test necessarily fails.
If you do not have to preserve the original array, you could do $big = shift @array; instead.
We will leave it to the OP to find a way to avoid the unnecessariy extra turn of the loop and still maintain the original array (without using an extra variable to save the shifted value).
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Printing largest number in array using loops and if statement
by FunkyMonk (Bishop) on Jan 17, 2010 at 00:09 UTC | |
by CountZero (Bishop) on Jan 17, 2010 at 07:48 UTC |