Hi,
Is there a way to repeat a set of code until a certain if statement is
satisfied. If it is then to exit the loop and if not repeat the code?
Say I want to write a card game application in PHP and I want to chose a
card from the deck $card1 = rand(1,52); gets me my first card.
I need to record which card has been dealt so I have a variable $dealt which
starts out as a string of 52 zeros. I update the position of $card1 in the
$dealt string to "1".
So the 5 of Spades makes $dealt = "00001000000000 0 ..."
I want to choose another card so I use $card2 = rand(1,52); and then need to
check if it has already been dealt. If the position in $dealt is a 1 then I
need to repeat the random number code until it is a 0 when I can update it
to a 1 and move on ...
Or is there a better way of doing this sort of thing ??
Help, as always, appreciated.
Paul.
Is there a way to repeat a set of code until a certain if statement is
satisfied. If it is then to exit the loop and if not repeat the code?
Say I want to write a card game application in PHP and I want to chose a
card from the deck $card1 = rand(1,52); gets me my first card.
I need to record which card has been dealt so I have a variable $dealt which
starts out as a string of 52 zeros. I update the position of $card1 in the
$dealt string to "1".
So the 5 of Spades makes $dealt = "00001000000000 0 ..."
I want to choose another card so I use $card2 = rand(1,52); and then need to
check if it has already been dealt. If the position in $dealt is a 1 then I
need to repeat the random number code until it is a 0 when I can update it
to a 1 and move on ...
Or is there a better way of doing this sort of thing ??
Help, as always, appreciated.
Paul.
Comment