Kevin Ponds wrote:
Brian,

Your while loops aren't actually performing any operation on the variable

I did actually state that the loops wouldn't work.

I adjusted them to better show what I want to achieve, not to show how I am trying to achieve it.

that is being tested as part of their condition.  With while loops, if the
condition ($i in this case) is true at the start of the loop, and doesn't
change, they will loop forever.  They aren't like for loops, where you
pre-declare the increment operation that's ran every loop.  You need to add
some kind of code to increment the $i for each iteration of the loop such
that the condition eventually becomes false.  I'm not sure exactly what
logic you would use to do that, as I'm having a hard time figuring out what
these loops are supposed to do.

I've tried using while, if and for in different ways, whilst some permutations worked partially, I haven't been able to figure out the correct way of laying the code out to do a couple of basic tests. I'm going back and forth on something that looks to me like it should be so damned simple to figure out.


That being said, I think you would realize some benefit by stepping back and
looking at the overall design of your program, breaking it down into
subroutines and thinking about the clearest way to implement it.  I think
there are several ways to refactor this to make it much easier to write,
debug, and maintain.

Yes I agree, but whilst I am at a point where I am having trouble working out one simple step, I really don't think it a good idea to break it into loads of subroutines. I get confused easily, as can be seen by my inability to solve the problem below.


On Fri, Apr 17, 2009 at 3:46 PM, Brian <brian5432...@yahoo.co.uk> wrote:


for ( $i <=10; $i += 1 ; ) {

while ($i == 1 ) {

       if  ($mystart < 1 ) {
                       print "
                               <td width="27" height="27"><div
align="center" class="style4"></div></td>"
}

       if  ($mystart > 0 ) {
                       print "
                               <td width="27" height="27"><div
align="center" class="style4">$mystart</div></td>"
}
}
}
while ($i == 2..10 ) {

while ($i > 1 ) {

       if  ($mystart < 1 ) {
                       print "
                               <td width="27" height="27"><div
align="center"></div></td>"
}

       if  ($mystart > 0 ) {
                       print "
                               <td width="27" height="27"><div
align="center">$mystart</div></td>"
}
}
}
#}



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to