Thread Rechenproblem
(8 answers)
Opened by bianca at 2011-05-15 16:08 2011-05-15T14:32:58 bianca Ich würde int($anzahl/$max) nur einmal berechnen und die Schleife übersichtlicher machen: Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 my $max = 10; my $anzahl = 451; my $step = int($anzahl/$max); my $lfd = 0; foreach my $nr (1..$anzahl) { next if $anzahl > $max and $nr % $step; $lfd ++; print "Nr. $nr kommt rein, Anzeige Nr. $lfd\n"; } Output: Code: (dl
)
1 Nr. 45 kommt rein, Anzeige Nr. 1 Dabei fallen die Randelemente ggf. weg. Wenn das ok ist, voilá. Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? -- Brian Kernighan: "The Elements of Programming Style"
|