Killer loop crashes my computer when checking

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Killer loop crashes my computer when checking

Post by Perfidus »

I'm trying to generate a loop for the Months of the year in Spanish and also another for the days of the months, I have check it a couple of times but I can't see what's wrong, and it crashes my PC.
:oops:

Code: Select all

<?
$mesencurso = date("n"); 
$meses=array("","Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"); 
$dias=array(0,3,28,31,30,31,30,31,30,31,30,31,30);
$value=count($meses);
$desp=($mesencurso+13);
if($desp>$value){
$desp2=$desp-$value;
$desp1=$value-$mesencurso;
for($m=$mesencurso;$m<$value;$m++){
$mreal=$m-1;
echo "<option value=\"controlpannel.php?varm=".$mreal."\">".$meses[$m]."</option>";
}
for($m=1;$m<$desp2;$m++){
$mreal=$m-1;
echo "<option value=\"controlpannel.php?varm=".$mreal."\">".$meses[$m]."</option>";
}
}else{
for($m=$mesencurso;$m<$desp;$m++){
$mreal=$m-1;
echo "<option value=\"controlpannel.php?varm=".$mreal."\">".$meses[$m]."</option>";
}}
if(isset($varm)){
$days=$dias[$varm];
}else{
$days=$dias[$mesencurso];
} 
for($d = 1; $d = $days; $d++){
echo "<option value=\"".$d."\">".$d."</option>";
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your code is seriously hard to read..

the "while" condition expression of the for loop on line 28 is at fault. Creating an infinite loop.
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Post by Perfidus »

Sorry for my messy code... :oops:
About line 28,
I can't not see the problem:

Code: Select all

for($d = 1; $d = $days; $d++){
It should stop when reaching $days, isn't it?
I need some basic advice, I'm afraid...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you're assigning $days to $d. If $days is non-zero, that's an infinite loop, no matter what you do pretty much.
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Post by Perfidus »

OOOOOPPPPS
I missed the double ==!
Post Reply