12-07mar01loops

# 12-07mar01loops - 1 CS100J 1 March, 2006 Loops, iterative...

This preview shows pages 1–4. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 CS100J 1 March, 2006 Loops, iterative statements, or repetitive statements Learning without thought is labor lost. Thought without learning is perilous. or, alternatively, Study without reflection is a waste of time; reflection without study is dangerous.-- Confucius Start reading Sec. 2.3.8 and chapter 7 on loops. The lectures on the ProgramLive CD can be a big help. 2 The for loop, for processing a range of integers x= 0; // add the squares of int s // in range 2..200 to x x= x + 2*2; x= x + 3*3; … x= x + 200; repetend : the thing to be repeated. The block: { x= x + i*i; } for each number i in the range 2..200, add i*i to x. The for-loop: for ( int i= 2; i <= 200; i= i +1) { x= x + i*i; } loop counter : i initialization : int i= 2; loop condition : i <= 200; increment : i= i + 1 repetend or body : { x= x + i*i; } 3 Execution of the for-loop The for-loop: for ( int i= 2 ; i <= 4 ; i= i +1 ) { x= x + i*i; } loop counter : i initialization : int i= 2; loop condition : i <= 4; increment : i= i + 1 repetend or body : { x= x + i; } Called a “flow chart” To execute the for-loop. 1. Execute initialization ....
View Full Document

## This note was uploaded on 03/03/2012 for the course CS 100J taught by Professor Davidgries during the Spring '07 term at Cornell.

### Page1 / 11

12-07mar01loops - 1 CS100J 1 March, 2006 Loops, iterative...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online