Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Me no good at Xing anything

by pzbagel (Chaplain)
on Aug 01, 2003 at 15:35 UTC ( [id://280004]=note: print w/replies, xml ) Need Help??


in reply to Multiplication table

Wow, that's a lot of output and next to no description of your problem. But I think you are trying to print out multiplication tables. You almost have it, however, your problem is that you are incrementing both of your counters simultaneously. In fact $counter and $counting are incremented one after the other. That leads to your problem where you get 0*1, then 1*2, etc. What you want is a nested loop. That is for each $counter, you want to iterate through $counting 10 times to print out the times table for that number, then print the newline, increment $counter, and continue. Here's a basic example with for loops(They're your friend)

for my $x (1..$howmany) { print "#"; for my $y (1..10) { my $answer = $x * $y; print "|$x|*|$y|=|$answer"; } print "\n"; }

Notice how one for loop is nested in the other, so for every iteration of $x which goes from 1 through $howmany, you get 10 iterations of $y. performing the math and printing inside the second for loop and you are done. No fuss, no muss, and no tracking of several counter variables.

HTH

Log In?
Username:
Password:

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

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

    No recent polls found