Join Mark Niemann-Ross for an in-depth discussion in this video Teacher's guide: Basic logic with if-then-else, part of Teach Kids Programming with PHP.
- View Offline
Just a reminder, this video is just for the teacher. I'll be talking pretty fast and might even give away the challenge part of the chapter. If your student is watching, stop the video and have them do something else for a minute. The real power of a computer is the ability to make a decision, and the most basic form of a computer decision is an if-then statement. It looks pretty much the same in PHP as it does in any other language. For example, if followed by a test that will either be true or false, followed by then, and the code that should be run if the test is true.
An if-then-else statement looks very similar. If, followed by a test that will be either true or false, followed by then, and some code that will run if the condition is true, followed by else, and a block of code that should execute if the test is false. Here is what an if-then-else statement looks like in PHP. Our goal in this chapter is learning logical decisions, which may be an entirely new concept to a beginning learner.
Since you've been programming for some time, if-then statements are entirely second nature. But for someone just starting out, they may not have ever considered such a thing exists. Even if they use it every day. For example, if I take out the trash, then I can have my allowance. It's highly likely they have never seen the computer expression of a logical statement. By the end of this chapter your student will have seen a logical statement, played with it, and written one of their own. We'll also talk about comparison operators.
Mm, equal to, not equal to, less than, greater than, less than or equal to, greater than or equal to. And we'll also briefly discuss PHP punctuation including semi-colons, parenthesis and curly braces. Like the last chapter, you'll want to keep an eye on these punctuation elements and help your student if they accidentally delete one. Before you start the next video, use your PHP editor to open daysInMonth.php. Arrange the lynda.com video, your PHP editor and the web browser, so you can easily find them when needed.
One final note. If you're typing, the student isn't learning. Let them control the keyboard. You're here to nudge them into the lesson and help them get unstuck. Okay, when you're ready, let's get started teaching a kid to program.
- Teacher's Guide: Introduces the concepts in the chapter and preps the adult on places where the student might get stuck
- Try It: Immediately engages the student, showing working code in action
- Check It Out: Encourages the adult and student to engage with and edit some existing code
- The Facts: A lecture for the student to watch
- Extend It: An exploration of expanded and extended concepts
- Challenge: A hands-on coding challenge for the student
- Solution: A step-by-step solution presented by the author
This course, in essence, acts as a lesson plan to help you teach PHP to a beginner. Its structured curriculum supports those who have a solid understanding of PHP, but don't necessarily know how to teach PHP effectively to kids.