使用while循环

时间:2015-12-19 18:04:48

标签: php

我试图制作一个while循环,告诉我什么时候我已经在模具上滚动了6。你能帮我解决下面的问题吗?

<!DOCTYPE html>
<html>
    <head>
        <title>Your own do-while</title>
        <link type='text/css' rel='stylesheet' href='style.css'/>
    </head>
    <body>
    <?php
    $roll = 1

    while ($roll != 6);
    {
        $roll = rand(0,6);
        echo "Rolled a ". $roll . "<br>"; 

    }
    echo "You finally rolled a ". $roll;

    ?>
    </body>
</html>

2 个答案:

答案 0 :(得分:1)

如评论中所述进行的更改似乎正常。

<!DOCTYPE html>
<html>
    <head>
        <title>Your own do-while</title>
        <link type='text/css' rel='stylesheet' href='style.css'/>
    </head>
    <body>
    <?php

    $roll = 1;

    do {
        $roll = rand(1,6);/* Dice are numbered from 1-6, not 0-6! */
        echo "Rolled a ". $roll . "<br>"; 

    } while ( $roll !== 6 );
    echo "You finally rolled a ". $roll;

    ?>
    </body>
</html>

答案 1 :(得分:-1)

     {
    $roll = rand(0,6);
    echo "Rolled a ". $roll . "<br>";
    $roll++;

}

你应该添加&#39; $ roll ++&#39;在

的时候