Lesson 15
Part III (Introduction to Programming, continued)
A very important part of writing programs is to be able to do something based on a particular value. For example, checking to make sure the user is inputting valid values. Would it be reasonable for a user to input a test score of -20 or 152? Well, 152 might be reasonable if the test was based on 200 points, but -20 is not reasonable!
1. The Ctrl Menu

2. Using an If Then Statement
We can use an If Then statement to check for valid input or perform different actions based on input. The “syntax” of an If Then statement is as follows:

3. Walking Through a Program
An excellent way to understand programming is to do what is called a code walk through. To “walk” through code, we make up values as needed and then walk the value through the code. For example, consider these programs:
(a) This is a walk through of program (a) shown below.
If we run this program, what happens?
- We input a number. Assume you input 12.
- 12 is stored in n (n=12).
- 12 > 10, so "Large number!" is printed.
- Program ends.
If we run the program again, what happens?
- We input a number. Assume you input 5.
- 5 is stored in n (n=5).
- 5 > 10 is false.
- Program ends (nothing is printed).
(b) Using a pencil and paper, try walking through program (b) with n=1, n=15 and n=-3. Write down what you think the output will be for each. When finished, type in the program and then run it with n=1, n=15 and n=-3. How do these answers compare with your walk through results?
(c) Try walking through program (c) with n=1, n=15 and n=-3. This program is organized a little better. Remember, programs will do exactly what we instruct them to do.

Part III
Practice Exercises
- Begin a new program named Drive by clicking
and inputting the program name. - Write a program (using an If Then Else statement) that will do the following:
- Ask the user what their name is.
- Ask the user their age.
- Display the user's name.
- On the next output line:
- If they are 15 years or older, display the message: You can drive the car.
- If they are between 5 years and 14 years of age, display the message: You can ride the bicycle.
- If they are under 5 years of age, display the message: Ask your mother or father for a ride.
- If they are less than 0 years old, display the message: You are not born yet!
- Run your program and input an age of 15. With the output window showing, get a screen capture. Paste it into your Lesson15 document (under a title of PART III).
- Run your program and input an age of 8. With the output window showing, get a screen capture. Add two blank spaces following the first screen capture and then paste this one.
- Run your program and input an age of 3. With the output window showing, get a screen capture. Add two blank spaces following the last screen capture and then paste this one.
- Run your program and input an age of -43. With the output window showing, get a screen capture and then paste it on the next line.
Part IV
Reflection Exercises
You have just completed the fifteenth lesson in ClassPad 101. We will continue to write programs in Lesson 16; try to complete Lesson 16 right away. Please take a few moments to copy and paste the following three questions at the end of your Lesson15 document and answer them.
- Approximately how long did it take you to complete this lesson?
- Which activity did you find particularly useful?
- Did you find any part of this activity difficult to follow? If so, which part? Also, how did you overcome the difficulty?
Assessment 15: Introduction to Programming
- Checkpoint: Your word processed document, titled "Lesson15", should contain the following activities:
- Three screen captures from PART I
- Three screen captures from PART II
- Four screen captures from PART III
- Three reflection questions with answers from PART IV
- Submit your Lesson15 document to your instructor for grading. Once your lesson is submitted, your lesson for ClassPad 101 “Intro to Programming ” is complete.