Jump to content

how to rest a for loop


Trium918

Recommended Posts

This for loop runs 7 times. When the loop reaches

it ending,  I need away to rest the loop back to 1

when the user clicks the correct button.

 

<?
  //Simple Array tha has a value 
  //assigned to it
  $remark[1] = "My first number is:";
  $remark[2] = "My Second Guess is:";
  $remark[3] = "Three";
  $remark[4] = "Four";
  $remark[5] = "Five";
  $remark[6] = "Six";
  $remark[7] = "Seven";
   
  echo "<form method=\"GET\">";
  echo "<input type=\"submit\"  name=\"Guess\" value=\"Guess\">";   
  echo "<input type=\"submit\"  name=\"Higher\" value=\"Higher\">";   
  echo "<input type=\"submit\"  name=\"Lower\" value=\"Lower\">";  
  echo "<input type=\"submit\"  name=\"Correct\" value=\"Correct\">";   
   
  $valuecheck = $_GET['count']; 
  
  //For Loop
  for ($i = 1; $i <= 7; $i++)
  {
   if( $valuecheck == $i){
  		process();
   }
  }//End of the For Loop
  
   $count++; //Counter
  
  function process(){
    global $guess,$max,$min,$count,$remark,$i;

  	if($_GET["Guess"]){
   	  $guess=50;
  print"<h2>$remark[$i] $guess<br></h2>";
  $max = 100;
  $min = 0;  
   }
    else if($_GET["Higher"]){
   	  $min = $guess;
  $guess = round($guess + (($max - $min)/2));
  print"<h2>$remark[$i] $guess <br></h2>";
  print"max = $max min = $min </h2>";
  print"count = $count";
   }
    else if($_GET["Lower"]){
   	  $max = $guess;
  $guess = round($guess -(($max - $min)/2));
  print"<h2>$remark[$i] $guess <br></h2>";
  print"max = $max min = $min </h2>";
  print"count = $count";
   }
  }//End of function process()
  
   if($_GET["Correct"]){
   
   }
   
   echo "<input type=\"hidden\"  name=\"count\" value=\"$count\">";   
   echo "<input type=\"hidden\"  name=\"guess\" value=\"$guess\">";   
   echo "<input type=\"hidden\"  name=\"max\" value=\"$max\">";  
   echo "<input type=\"hidden\"  name=\"min\" value=\"$min\">";  
   echo"</form>"; 
?>

The word is "reset" not "rest". The function is reset(), not rest(). But that won't help you.  Just put

<?php
$count = 1;
?>

in this area:

<?php
if($_GET["Guess"]){
  $guess=50;
  print"<h2>$remark[$i] $guess<br></h2>";
  $max = 100;
  $min = 0;
  $count = 1;
}
?>

 

Ken

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.