12-07mar01loops

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

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 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 refection is a waste oF time; refection 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 “fow 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 / 2

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online