Jump to content

[SOLVED] While Loop not working properly


dazman

Recommended Posts

I know the answer is just me, but I am new to this.

 

I am trying to run the following script but i am having all sorts of problem output. At the moment the script is just generating the number 1.

 

I am not familiar with php code, and i have read the manual on while loops. I dont have a debugger, could you suggest a good one for me perhaps, if anyone could let me know what I have done wrong here it would be greatly appreciated.

 

<?php
/* This is a script that is supposed to generate random numbers from 1-45. Each time it generates a new random number the count of the randomly
generated numbers is noted. If a random number that is generated is equal to 44, 10, 16, 12, 22 or 20 the script adds to a counter.
Once the counter reaches 3 the script will end and the noted amount of random numbers the script generated it output.  */
set_time_limit(500);
$counter = 0;
$randomnumbercounter = 0;
while($counter < 3) {
$random = rand(1,45);
if ($random = 44) { 
	$counter++;
}
if ($random = 10) { 
	$counter++;
}
if ($random = 16) { 
	$counter++; 
}
if ($random = 12) { 
	$counter++; 
}
if ($random = 22) { 
	$counter++; 
}
if ($random = 20) { 
	$counter++;
}	
$randomnumbercounter++;
}
echo '<BR>';
echo $randomnumbercounter;
?>

Link to comment
https://forums.phpfreaks.com/topic/160778-solved-while-loop-not-working-properly/
Share on other sites

To be honest I've never looked for, or know if a 'debugger' as such exists. If you use a text editor it will show you syntax errors. Though it wouldn't have shown anything in your case as you weren't doing anything wrong as far as php is concerned, just different to what you wanted.

 

Take a look at notepad++ http://notepad-plus.sourceforge.net/uk/site.htm

 

It's a free source code editor

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.