Author Topic: Need help with for loop  (Read 480 times)

Offline herki18

  • Level 3
  • *
  • Posts: 6
  • Reputation: +0/-0
    • View Profile
Need help with for loop
« on: February 28, 2009, 07:03:58 PM »
this program produce infinity loop what i do wrong sry bad english
Code: [Select]
$min = 6000;
$max = 6000;
$planetsStep = 6000;
$count = 4500;
$stepp = 500;
$layers = 7;
$i = 0;

for($ii = 0; $ii < $layers; $ii++)
{
$max += $planetsStep;
for($i; $i < $count; $i++)
{
$data['x'][$i] = rand($min, $max);
$data['y'][$i] = rand($min, $max);
$data['z'][$i] = rand($min, $max);

$name[$i]  = "x: ";
$name[$i] .= intval($data['x'][$i]);
$name[$i] .= " y: ";
$name[$i] .= intval($data['y'][$i]);
$name[$i] .= "z: ";
$name[$i] .= intval($data['z'][$i]);
}
$i = $count;
$count += $count;
$count -= $stepp;
$min = $max;
}

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Need help with for loop
« Reply #1 on: March 01, 2009, 07:22:13 AM »
Code: [Select]
$min = 6000;
$max = 6000;
$planetsStep = 6000;
$stepcount = 4500;
$count = $stepcount;
$stepp = 500;
$layers = 7;
$i = 0;

for($ii = 0; $ii < $layers; $ii++)
{
$max += $planetsStep;
for($i; $i < $count; $i++)
{
$data['x'][$i] = rand($min, $max);
$data['y'][$i] = rand($min, $max);
$data['z'][$i] = rand($min, $max);

$name[$i]  = "x: ";
$name[$i] .= intval($data['x'][$i]);
$name[$i] .= " y: ";
$name[$i] .= intval($data['y'][$i]);
$name[$i] .= "z: ";
$name[$i] .= intval($data['z'][$i]);
}
$i = $count;
$count += $stepcount;
$count -= $stepp;
$min = $max;
}

Offline herki18

  • Level 3
  • *
  • Posts: 6
  • Reputation: +0/-0
    • View Profile
Re: Need help with for loop
« Reply #2 on: March 01, 2009, 09:06:19 AM »
thanks chris.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal