Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Perl Loops

by farang (Friar)
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.


Comment on Re: Perl Loops
Select or Download Code
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
Node Status?
node history
Node Type: note [id://1041514]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-04-21 01:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (489 votes), past polls