marain
08-30-2018, 10:52 PM
Hi Folks,
Back again with a new problem. I think it's a simple one, but it escapes me:
There are sixty-four buildings numbered building one through building sixty-four. I want to "visit" each of the buildings one time, selecting the building to be visited in random order, but I do not want to visit building six at all. The code accomplishes that seemingly perfectly, except that after reaching the loop limit, I'm echoing one last time, with the building number blank. Here's the code:
$buildings = range (1, 64);
$building_index = 1;
shuffle ($buildings);
while ($building_index < 65) {
if ($buildings[$building_index] !== 6 ){
echo "Building " . $buildings[$building_index] . " All hail Caesar!<br />";
}
$building_index ++;
}
Here are the last three lines of what the above code produces:
Building 4 All hail Caesar!
Building 56 All hail Caesar!
Building All hail Caesar!
What am I missing?
A.
Back again with a new problem. I think it's a simple one, but it escapes me:
There are sixty-four buildings numbered building one through building sixty-four. I want to "visit" each of the buildings one time, selecting the building to be visited in random order, but I do not want to visit building six at all. The code accomplishes that seemingly perfectly, except that after reaching the loop limit, I'm echoing one last time, with the building number blank. Here's the code:
$buildings = range (1, 64);
$building_index = 1;
shuffle ($buildings);
while ($building_index < 65) {
if ($buildings[$building_index] !== 6 ){
echo "Building " . $buildings[$building_index] . " All hail Caesar!<br />";
}
$building_index ++;
}
Here are the last three lines of what the above code produces:
Building 4 All hail Caesar!
Building 56 All hail Caesar!
Building All hail Caesar!
What am I missing?
A.