How do I fix the infinite loop?


#1


https://www.codecademy.com/en/courses/web-beginner-en-5YvPF/0/7?curriculum_id=5124ef4c78d510dd89003eb8#

How do I make it not be infinite?


	</head>
	<body>
	<?php
	$roll = true; 
	
    $rollCount = 0; 
    do {
        $roll = rand (1, 6); 
        $rollCount++;
        switch (6) {
            case 0:
            	echo "<div class=\"coin\">1</div>";
            case 1: 
            	echo "<div class=\"coin\">2</div>";
            case 2:
            	echo "<div class=\"coin\">3</div>";
            case 3: 
            	echo "<div class=\"coin\">4</div>";
            case 4: 
            	echo "<div class=\"coin\">5</div>";
            case 5: 
            	echo "<div class=\"coin\">6</div>";
        }
        }while($roll);
        $verb = "were";
        $last = "rolls"; 
        if ($rollCount == 1) {
            $verb = "was";
            $last = "roll"; 
        }
        print "<p> There {$verb} {$rollCount} {$last}!</p>";
        $roll = false;
        ?>
        </body>
    </html>


#2

The expression is never found in a case so the loop goes forever. Change to

switch ($roll) {

There needs to be some form of exit condition in the loop. It can be based upon $rollcount, or you could add one more case,

case 6:
    echo "<div class=\"coin\">6</div>";

Set the others to match their case, and use case 0 to break

case 0:
     break;

Then change to rand(0, 6)