我在理解以下递归代码时遇到一些麻烦:
<!DOCTYPE html>
<html>
<head>
<link type='text/css' rel='stylesheet' href='style.css'/>
<title>More Coin Flips</title>
</head>
<body>
<p>We will keep flipping a coin as long as the result is heads!</p>
<?php
$flipCount = 0;
do {
$flip = rand(0,1);
$flipCount ++;
if ($flip){
echo "<div class=\"coin\">H</div>";
}
else {
echo "<div class=\"coin\">T</div>";
}
} while ($flip);
$verb = "were";
$last = "flips";
if ($flipCount == 1) {
$verb = "was";
$last = "flip";
}
echo "<p>There {$verb} {$flipCount} {$last}!</p>";
?>
</body>enter code here
</html>
$flipCount
如何获得$flip
的数量?我不明白怎么解释呢?
答案 0 :(得分:0)
Euh ...因为$flipCount ++
,相当于$flipCount = $flipCount +1
?