- Activity:
int i = 1; double result = 1; while (i < 9){ result = result + i; i = i + 2; }
- Tell students you’re going to trace the value of i during the loop execution.
- Draw a table on the board that will show the current value for i and result.
- Cross out each row in the table as the code iterates to make it clear to students that the previous values are no longer available.
- The table should look like the table below:
result i 1.0 1 2.0 3 5.0 5 10.0 7 17.0 9
- Show students the following code: