Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Perl Loops

by farang (Chaplain)
on Jun 29, 2013 at 21:04 UTC ( #1041514=note: print w/replies, xml ) Need Help??

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!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041514]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2016-10-28 12:37 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (383 votes). Check out past polls.