Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I'm a freelance consultant, and your site's helped me with many issues. I just wanted you to know that someone does appreciate the intelligent help your site offers."

Geography

Where in the world do Tek-Tips members come from?

annoying for loop errorHelpful Member!(2) 

fortytwo (TechnicalUser)
31 Aug 00 11:22
Hi, I have this for loop and it is looping three times:

for ($i = 0, $i <= $noinsection, $i++)
  {
  print $i;
  }


even though $noinsection is 1.  $i prints as 1 each time.

Anyone got any ideas?

fortytwo
will@hellacool.co.uk
my test site

Helpful Member!  rbobbitt (Programmer)
31 Aug 00 20:58
You're using commas where you should be using semicolons. Try this instead:

for ($i = 0; $i <= $noinsection; $i++)
{
    print $i;
}


Regards

fortytwo (TechnicalUser)
1 Sep 00 4:33
Hi, Thanks for that.  I guess because I didn't get an internal server error I thought the error lay elsewhere.

One thing, how did the first code section only run three times then exit?

fortytwo
will@hellacool.co.uk
my test site

Helpful Member!  sesth (Programmer)
1 Sep 00 11:31
I think perl uses your for-head as a list. The list ($i = 0, $i <= $noinsection, $i++) has three elements and is evaluated before entering the loop. $i is set to 0 and incremented at last resulting to 1. The loop iterates 3 times because the list has 3 elements. The current value of $i (1) is printed.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close