Jump to content

Recommended Posts

I'm building a nice big web app and I'm starting to run low of letters to use for variables and looping needs..

 

I know i can create local variables but I can't seem to get them to work so i'm assuming i'm not using them correctly thats what i need some help with..

 

I want to do this...

 

while($i=0;$i<=15)
{
DO THIS BALH
}

while($i=0;$i<=100)
{
blah blah do this
}

 

instead of...

 

$i=0;
$y=0;

while($i<=15)
{
blah do this
}

while($y<=100)
{
blah do this and htis
}

 

any suggestions??

 

thanx alot everyone,

 

ag3nt42

as long as you don't need the variable further down in your script. You can just keep using the same one over and over again. PHP will just keep re-assigning it. The only time you have to redeclare it is when you need that value later in the script.

 

Ray

With a for loop, you are executing a specific amount of iterations. With a while loop, you are executing it indefinitely until the condition is false.

 

The usefulness of a while loop is for instance when you are retrieving info from a database and you don't necessarily know how many results are going to be returned, so you don't really know how many iterations to make the loop.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.