Griff Posted April 17, 2014 Share Posted April 17, 2014 Having a pain in the ass of a time figuring out how to get this to work properly... Goal: have script roll untill it hits a 6 and echo out each result untill it does so. i'm probably just not doing something very simple any help is appreicative been years since i've touched PHP and trying to re-learn. do { $roll = rand(0,6); while ($roll != 6){ echo "You Lose you Rolled a {$roll}"; $roll; } else ($roll = 6) { echo "You win you Rolled a {$roll}!"; } Quote Link to comment Share on other sites More sharing options...
dalecosp Posted April 17, 2014 Share Posted April 17, 2014 Set a flag. $rolled = false; while (!$rolled) { $roll = rand(0,6); if ($roll == 6) { echo 'You rolled a six! You Win!'; $rolled=true; } else { echo "You Lose! You rolled a $roll"; } } Quote Link to comment Share on other sites More sharing options...
dalecosp Posted April 17, 2014 Share Posted April 17, 2014 The do-while version: $rolled = false; do { $roll = rand(0,6); if ($roll == 6) { echo 'You rolled a six! You Win!'; $rolled=true; } else { echo "You Lose! You rolled a $roll"; } } while ($rolled==false); Quote Link to comment Share on other sites More sharing options...
Griff Posted April 17, 2014 Author Share Posted April 17, 2014 Thanks, that makes much mores sense stupid self imposed exerisices to help you see if you remember stuff. Quote Link to comment Share on other sites More sharing options...
kicken Posted April 17, 2014 Share Posted April 17, 2014 Alternate do-while version: do { $roll = rand(0,6); if ($roll != 6){ echo 'You lose! You rolled a '.$roll; } } while ($roll != 6); echo 'You rolled a six! You Win!'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.