Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Perl Loops

by farang (Chaplain)
on Jun 29, 2013 at 21:04 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found