Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
amprog_05_ex1 [2017-09-01 14:54]
127.0.0.1 external edit
amprog_05_ex1 [2017-10-19 09:40]
Anders Mosshäll
Line 14: Line 14:
     $slump = mt_rand(1,10);     $slump = mt_rand(1,10);
            
-    $slumpaom = false;        // Utgå från att talet är unikt.+    $exist = false;           // Variabel för att kolla om talet finns
          
-    $= 0; +    $= 0; 
-    while ($< count($tal)){ // Finns talet redan i arrayen?   +    while ($< count($tal)){ // Finns talet reda i arrayen?   
-      if ($tal[$x] == $slump){ +      if ($tal[$j] == $slump){ 
-        $slumpaom = true;+        $exist = true;
       }       }
-      $x++;+      $j++;
     }     }
          
-    if ($slumpaom == false){  // Lägg till talet i arrayen om det är unikt.+    if ($exist == false){  // Lägg till talet i arrayen om det är unikt.
       $tal[] = $slump;       $tal[] = $slump;
 +      $slumpaom = false;   // För att avbryta loopen
     }     }
   }   }
Line 33: Line 34:
 //Skriv ut arrayen. //Skriv ut arrayen.
  
-$= 0; +$= 0; 
-while ($< count($tal)){ +while ($< count($tal)){  
-  echo $tal[$x].'<br>'; +  echo $tal[$i].'<br>'; 
-  $x++;+  $i++;
 } }