Do while question in PHP module


#1

In the following code;
<?php
$headCount = 0;
$flipCount = 0;
while ($headCount < 3) {
$flip = rand(0,1);
$flipCount ++;
if ($flip){
$headCount ++;
echo "

H
";
}
else {
$headCount = 0;
echo "
T
";
}
}
echo "

It took {$flipCount} flips!

";
?>

Could someone tell me why,
if ($flip){
$headCount ++;
echo "

H
"

assigns a value of 1 to the heads condition? The do while code is easy enough to understand but I am not seeing how heads gets the value of 1 from $flip = rand(0,1);


#2

please excuse the lousy code structure. The copy paste did not post the way the code was laid out. :frowning:


#3

To format your code to make it visible:
1. Paste your code.
2. Select all of your code.
3. Do Ctrl + Shift + C (Windows) or CMD + Shift + C (Mac OSX) to format your code.

OR

  1. Paste your code in.
  2. Insert 3 backticks (`) before and after your code:

Code goes here

thanks @jibblyj