Lecture 17: More For Loops
Monday, April 02, 2012
Reading Assigned: 5.4 - 5.8
Homework Due: None
Homework Assigned: Homework 08 -- last class
Classwork Assigned: Classwork 10
Topics Covered:
- Quiz 2 - Results
- Most common programming errors:
- Wrong syntax for function signature (-2 to 3 points)
- Return when function returns no values (-1 point)
- Unnecessary use of scanf for input arguments (-2 points)
- Return() is invalid syntax (-1 point)
- Using printf to output values instead of returning (-2 points)
- Defining variables that shadow arguments (-2 points)
- For loops
- Reminder:
- For loops consist of the following syntactical elements
- for ( INIT; TEST; INCREMENT) { code; }
- INIT, TEST, and INCREMENT are normally expressions
- A common for loop looks like:
int x; for(x=0; x<10; x=x+1) { printf("x is %d\n", x); }
- Will produce the following output
0 1 2 3 4 5 6 7 8 9