Not getting the basics of loop


In trying to check if I'm grasping the basics I posed myself a little challenge (which I'm faling at)

re. the coin flip loop, I'm trying to make one where:
1. coinflip is done as in this exercise (this is 1 coinflipseries)
2. It does 100 coinflipseries
3. It then tells me what the average coinflips was for each series

However I can only manage to:
1. do one coinflip series
2. it then reprints the result of this series 100 times

How do I get this to work?

	$headCount = 0;
	$flipCount = 0;
	$seriesCount = 1;
	$totalFlips = 0;
    while ($seriesCount < 101) {
		while ($headCount < 3) {
			$flip = rand(0,1);
			$flipCount ++;
			if ($flip){
				$headCount ++;
				echo "<div class=\"coin\">H</div>";
			else {
				$headCount = 0;
				echo "<div class=\"coin\">T</div>";
		echo "<p>It took {$flipCount} flips!</p>";
		$totalFlips = $totalFlips + $flipCount; //this works like intended
		echo "<p>This was coinflipseries {$seriesCount} - Now in total {$totalFlips} flips</p>"; //this works like intended
		$seriesCount ++; //this works like intended
		// I can't get it do a fresh series, it will just re-print the nr of rolls needed for the first series 100 times
	$avgFlips = $totalFlips / ($seriesCount - 1); //Don't understand why I have to add the "-1" to divide by 100 instead of 101??
	echo "The average flips per series was {$avgFlips}"; //This works like intended


One thing to get you moving along would be to fix your incrementing operators.

You shouldn't have a space between the variable name and the operator:

$flipCount ++
$headCount ++