lecture_05_iteration_6p - Lecture 5: iteration for loops 1....

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

View Full Document Right Arrow Icon
1 1. Basic structure of a for loop 2. Breaking a loop 3. Indefinite loops Lecture 5: iteration “for” loops If you want to repeat a task several times, and you know The number of times Where you start, where you end By how much you increment each time Then you can use a for loop The structure of a for look is as follows for (structure which encodes how many times to do the loop) Whatever you want to do in the loop end “for” loops Example: this example shows how to incrementally create an array of size prescribed by the user. The user enters elements one by one User enters size of array Iterates until sizeOfArray Takes user input at each iteration “for” loops Example of execution: the user enters 5 (i.e. an array of size 5), and progressively enters the numbers in the array (in the present case, numbers from 1 to 5) “for” loops Typically, loops are used to iteratively modify the variables in your code. Need to initialize
Background image of page 1

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

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

This note was uploaded on 09/07/2011 for the course ENGIN 7 taught by Professor Horowitz during the Spring '08 term at University of California, Berkeley.

Page1 / 3

lecture_05_iteration_6p - Lecture 5: iteration for loops 1....

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