in reply to Bad While Loop

our @alias = @profit; my $maxprofit = pop @alias; foreach (@alias){ $maxprofit = $_ if $maxprofit < $_; } our $index = 0; ++$index until $profit[$index] == $maxprofit or $index > $#profit;

...

use List::Util qw(max); my $maxprofit = max @profit; our $index = grep { $profit[$_] eq $maxprofit } 0..$#profit;

Replies are listed 'Best First'.
Re^2: Bad While Loop
by riceboyyy (Novice) on Oct 25, 2011 at 23:34 UTC
    Thanks for the tip, but my original problem persists...it appears as if all variables remain unchanged throughout the loop

      lets see

      $A = ($a*($p1-$p2) + $b*($pT-$p1)/(-2)); $B = ($p1*($a*($p2-$p1) + $b*($pT-$p1)-$k*$d2-$d1i*$k));

      In your script $p1 = $p2, so this is the same as:

      $A = -0.5*$b*($pT-$p1); $B = $b*($pT-$p1)-$k*($d2-$d1i);

      What's the purpose of the var $p2?. Maybe you want to say:

      $p2 = $p1; $p1 += .01;

      Instead

       $p1 += .01; $p2 = $p1; ?

      Check that your equations are valid

        This was intentional. Later on in this project I'll be looking at what happens when p1 =/= p2, but for this case they are the same.