Thread for loop (10 answers)
Opened by nano at 2015-04-03 23:46

lichtkind
 2015-04-04 04:57
#180567 #180567
User since
2004-03-22
5697 Artikel
ModeratorIn + EditorIn
[Homepage]
user image
mein geschmack:


Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/perl

use v5.12;
use warnings;

say "please enter two odd numbers";
print "enter first odd number: ";
chomp (my $odd1 = <STDIN>);
print "enter second odd number: ";
chomp (my $odd2 = <STDIN>);
exit if $odd1 % 2 == 0 or $odd2 % 2 == 0; # exit unless $odd1 % 2 and $odd2 % 2;

my $step = $odd1 < $odd2 ? 2 : -2;
my (@odds);
for (my $i = $odd1; $i <= $odd2; $i += $step) {push(@odds, $i)};
say "numbers: @odds";

Last edited: 2015-04-04 13:26:57 +0200 (CEST)
Wiki:Tutorien in der Wiki, mein zeug:
kephra, baumhaus, garten, gezwitscher

Es beginnt immer mit einer Entscheidung.

View full thread for loop