|
-
May 11th, 2005, 07:47 PM
#1
Thread Starter
PowerPoster
While Loop
This may be a simple question but i'm trying to do a loop while one value doesn't equal the other but for some reason the loop never runs even if the values = each other. Can anyone help me out?
PHP Code:
while ($Number1 != $Number2) {
$Number2 = intval(rand(100, 999));
$Number1 = $Number2;
}
-
May 12th, 2005, 02:29 AM
#2
Fanatic Member
Re: While Loop
$Number1 = $Number2; statement false' the loop.
-
May 12th, 2005, 02:41 AM
#3
Re: While Loop
 Originally Posted by lintz
.. but for some reason the loop never runs even if the values = each other.
That would be correct. Right? If you want the the loop to execute at least once you use do..while:
PHP Code:
do {
$Number2 = intval(rand(100, 999));
$Number1 = $Number2;
} while ($Number1 != $Number2);
-
May 12th, 2005, 02:43 AM
#4
Fanatic Member
Re: While Loop
If initially the $Number1 and $Number2 differ on their values, that would at least execute once.
-
May 12th, 2005, 02:47 AM
#5
Re: While Loop
But if they are the same initially the while loop wouldn't execute. But I don't get it - they will always be the same, so where is the logic in putting a loop?
-
May 12th, 2005, 07:41 AM
#6
Lively Member
Re: While Loop
If there is no value set for each of the $Number variables before the loop, they would both equal 0, making the while loop not run, because they are equal.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|