L06 - CME/Energy 211 Margot Gerritsen Shela Aboud Emmet...

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

View Full Document Right Arrow Icon
CME/Energy 211 Margot Gerritsen Shela Aboud Emmet Caulfield
Background image of page 1

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

View Full DocumentRight Arrow Icon
Lecture Overview • Finish while and do-while loops • Enumeration Types: enum • Aggregate Type: struct • Union Type: union sizeof operator typedef • Aggregates type: arrays and strings
Background image of page 2
Example – Integration using for ) ( x f n a b h h i a f b f a f h dx x f b a n i = + + = 1 1 ) * ( 2 ) ( ) ( ) ( h Trapezoidal Rule x
Background image of page 3

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

View Full DocumentRight Arrow Icon
Iteration Statements – while while ( expression ) statement; • If expression is evaluated as nonzero (true) the statement continues to be executed. • The cycle is terminated when expression evaluates to 0 (false). • An omitted expression is replaced by a nonzero constant – infinite loop init_expr ; while ( test_expr ) { statement; loop_expr ; } while vs. for loops for ( init _ expr ; test_expr ; loop_expr ) { statement; }
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Iteration Statements – do-while do { statement; } while ( expression ); • The do - while loop executes the statement before checking if the expression is true, unlike the for and while loops which evaluate the expression before executing the statement . • Although braces are not required when only one statement is included, they should be used anyway to avoid confusion with the while loop.
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
return – used to return from a function; cannot be used if return type of function is void. goto – discouraged because it makes the code unreadable (condemnation cannot be too strong here!) break – used to terminate the a switch or iteration statement; may only be used in the body. continue
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/17/2010 for the course CME 211 taught by Professor Staff during the Winter '10 term at Stanford.

Page1 / 21

L06 - CME/Energy 211 Margot Gerritsen Shela Aboud Emmet...

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

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