While Loop in PHP (3) YOUR FIRST WHILE LOOP


#1


<!DOCTYPE html>
<html>
    <head>
		<title>A loop of your own</title>
        <link type='text/css' rel='stylesheet' href='style.css'/>
	</head>
	<body>
    <?php
	//Add while loop below
	$J = 100;
	while ($J>0) {
	    $J*=2;
	    echo "<p>$J*2</p>";
	    $J --;
	}
    
    ?>
    </body>
</html>


#2

This could cause a runtime error since you're constantly growing variable $J by double the amount and only decrementing by 1. This would cause a stack overflow, since you're pushing too many calls to the stack and all available memory is gone.

<!DOCTYPE html>
<html>
    <head>
		<title>A loop of your own</title>
        <link type='text/css' rel='stylesheet' href='style.css'/>
	</head>
	<body>
    <?php
	//Add while loop below
	$J = 100;
	while ($J > 0) {
	    echo "<p>$J*2</p>";
	    $J -= 10;
	}
    
    ?>
    </body>
</html>

#3

I am stuck since the code has been autosaved to the system. So, even if i
refresh the page, it reloads the same code. And I cant proceed from there,
is there a way to reset this????

Kindly help


#4

I would just delete everything by highlighting and backspacing or clear your cache


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.