Jump to content

Odd loop problem


sweinkauf13

Recommended Posts

Hello,Ok so this loop is the loop that will execute forever. The loop itself is self explanitory on what it should do. I just cant catch what is making it not break ever. If anyone can help me out that would be great. The loop code is posted below.

while($_SESSION[ohealth] > "0" && $_SESSION[health] > "0" && $_SESSION[ohealth] != "0" && $_SESSION[health] != "0"){	if($_SESSION[turn] == "0")	{#######User Turn########$num = math.rand(1,20);$a = $_SESSION[att_t] * $num;$attack = $a - $_SESSION[odef_t];$health = "$_SESSION[ohealth]";$h = $health - $attack;$_SESSION[ohealth] = "$h";$_SESSION[turn] = "1";	}	else if($_SESSION[turn] == "1")	{$num = math.rand(1,20);$a = $_SESSION[oatt_t] * $num;$attack = $a - $_SESSION[def_t];$health = "$_SESSION[health]";$h = $health - $attack;$_SESSION[health] = "$h";$_SESSION[turn] = "0";	}#}

Also I would like to add that all the SESSION varibles are full and none are left NULL. Thank you in advance,Youngwebmaster

Link to comment
Share on other sites

Why are you using strings instead of integers? That shouldn't be a problem, but it can get confusing. As for your issue, try echoing out the values of the session variables in question after every iteration, to see whether they are what you think they are.Also, if something is zero, then it is not greater than zero, so the last two tests in your while condition are superfluous.

Link to comment
Share on other sites

Hi!Try This CODE:xxxxxxxxxxxxxxxxxxx

<?PHP// Replaced:// math.rand(1,20)  to rand(1,20), math.round is java command, in php just use rand(1, 20);// $_SESSION[anything] to $_SESSION["anything"], Use Quotations In $_SESSION.// numeric values "0" to 0 or "1" to 1, Don't Use Quotations With Numeric Values (optional).// "$h" to $h, Don't Use Quotations With Variable Name (optional).while($_SESSION["ohealth"] > 0 && $_SESSION["health"] > 0 && $_SESSION["ohealth"] != 0 && $_SESSION["health"] != 0){    if($_SESSION["turn"] == 0)    {		$num = rand(1,20);		$a = $_SESSION["att_t"] * $num;		$attack = $a - $_SESSION["odef_t"];		$health = $_SESSION["ohealth"];		$h = $health - $attack;		$_SESSION["ohealth"] = $h;		$_SESSION["turn"] = 1;		print "Loop 1 Printed.<br />";    }    else if($_SESSION["turn"] == 1)    {		$num = rand(1,20);		$a = $_SESSION["oatt_t"] * $num;		$attack = $a - $_SESSION["def_t"];		$health = $_SESSION["health"];		$h = $health - $attack;		$_SESSION["health"] = $h;		$_SESSION["turn"] = "0";		print "Loop 2 Printed<br />";    }}?>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...