in reply to Perl Loops

Good that you are using strict and warnings, but you have to end the expressions with a semicolon.

use strict; use warnings; ...
Doing this will allow you to get information on problems in your code. You have a syntax error for the while line and a missing curly brace in the last line.

I'm fairly sure you are missing the purpose of this assignment, though. The only way it makes sense to me is for you to write four separate pieces of logic, each printing the numbers successfully. The only code you have close to doing this so far is part of one line.

print 2*$_, "\n", foreach (1..20);
This could be rewritten if you want as follows, but note you are still missing zero in the printout.
for ( 1..20 ) { print 2*$_, "\n"; }

I suggest you read the documentation carefully for while, until, for, and do in perlsyn and try some examples from there to see how you can write similar code which does what you want. Just having monks here give you working code will not have long-term value for you, but learning how to read documentation and produce working code yourself will be of great value.

Replies are listed 'Best First'.
Re^2: Perl Loops
by stamp1982 (Novice) on Jun 29, 2013 at 21:13 UTC
    Thank you! You were right. I though U was supposed to write one code but from your explanation I have to write four codes. It makes more sense since I also have to print out four times. Thank you!