Lecture 16-While Loop

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

This preview shows pages 1–5. 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 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 &quot;assignment&quot; &quot;P2 conflicts&quot; 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 &lt; p &lt; 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 ( &lt; condition &gt; ) { sequence of statements } boolean expression. = &quot;there's still stuff to do&quot; the &lt; repetend &gt; 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 &lt;= c ; k= k+1 ) { Process k; } // Process b..c int k= b ; while ( k &lt;= c ) { Process k; k= k+1; } Scope note : since k happened to be declared &quot;within&quot; 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 */ &lt;initialization&gt; ; while ( &lt;still input to deal with&gt; ) { 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
Ask a homework question - tutors are online