Lecture 16-While Loop - 1 CS1110 Lecture 16, 26 Oct 2010...

Info iconThis preview shows pages 1–5. 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

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 CS1110 Lecture 16, 26 Oct 2010 While-loops Reading for next time: Ch. 8.1-8.3 (arrays) Prelim 2 : Tu Nov 9 th , 7:30-9pm. Last name A- Lewis : Olin 155 Last name Li-Z: Olin 255 Conflicts? Submit CMS "assignment" "P2 conflicts" by today . Review session : Sun Nov 7 th , 1-3pm, Phillips 101. ( Set your clocks back the night before!) Reminder: A5 due Sat. Oct 30th. See assignments pg for hints on snowflake geometry. A mystery (due to von Neumann): suppose you have a biased coin with unknown probability of heads p, 0 < p < 1. How can you use this coin to simulate the output of a fair coin? (Answer: while-loops ) 2 Beyond ranges of integers: the while loop while ( < condition > ) { sequence of statements } boolean expression. = "there's still stuff to do" the < repetend > In comparison to for-loops : we get a broader notion of theres still stuff to do (not tied to integer ranges). But we must ensure that condition stops holding, since theres no explicit increment. condition repetend false true 3 Canonical while loops // Process b..c for ( int k= b ; k <= c ; k= k+1 ) { Process k; } // Process b..c int k= b ; while ( k <= c ) { Process k; k= k+1; } Scope note : since k happened to be declared "within" the loop, k cant be used after the loop. /* process a sequence of inputs where you don't know how many need to be taken care of */ <initialization> ; while ( <still input to deal with> ) { Process next piece of input; make ready for the next piece of input; } Heres one way to use the while loop 4 Interesting while loops (showing why they can be hard to understand) /** open question in mathematics: is...
View Full Document

This note was uploaded on 11/27/2010 for the course CS 9339 at Cornell University (Engineering School).

Page1 / 12

Lecture 16-While Loop - 1 CS1110 Lecture 16, 26 Oct 2010...

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

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