- There are two "control structures" we use when programming.
- These change the way the program executes.
- selection or if
- Repetition or looping.
- In our first algorithm
- Selection or an IF statement allows us to skip some instructions in the sequence.
- How about my routine in the morning
- Sometimes we might not have the else part.
- Think about leaving the house in the morning
get dressed
if it is cold out
put on a coat
get in the car
go to school.
- Sometimes it is a complex set, so we use
elseif
- My weekly routine
if it is Monday or it is Wednesday or it is Friday
Go to Programming II
Go to Intro to CS
Go to CSCI Systems Programming
else if it is Tuesday or it is Thursday
Go to Object Oriented Programming
else if it is Saturday
Do Saturday things.
else
DO Sunday things.
- Languages have different ways to implement selection, but the idea remains the same.
- Repetition is the second major control structure
- We can use various words, but
while
is very common
- These also take a decision
- And they repeat generally while the condition is true.
- My Life
while the semester is in session
do My Weekly Routine.
- Additionally we could use ideas like
foreach thing in a collection
- Grading
for each homework that was submitted
grade the homework
put the grade in the grade book
provide the student with feedback.