I realised that as a newbie I had decided to run before I could walk! This is bad bad bad for my understanding!
I have gone back to learn the basics of statements and while loops and carrying out variable exercises, just testing out crude examples and trying to make the logic stick!
I have an incredibly base question: I have some code:
<?php
$am = "am";
$pm = "pm";
// for ($hour > 5; $hour <=21){
// print "<br>";
// }
$hour = 6;
while ($hour <= 11){
print "<br> ". $hour.$am;
++$hour;
}
if ($hour > 11){
print "<br>".$hour.$pm;
}
while ($hour > 11){
print"<br> ". $hour.$pm;
++$hour;
}
?>
The premise is that I want to print out the number 6-21. 6-11 must be appended to am. numbers 12-21 must be appended to pm. (24hour clock thingy!).
My code is printing infinately, so I need to break the loop when $hour is incremented to 21.
I have a vague undestanding of for loops (like the commented out bit of the code) but I am not sure how to intergrate it with the rest of the code.
I am also aware that there are probably more elegant ways of doing this.
Any pointers or feedback greatly appreciated!
Trufla the noob!