{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture_05 - ECE 190 Lecture 05 February 1 2011 Control...

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

View Full Document Right Arrow Icon
ECE 190 Lecture 05 February 1, 2011 1 V. Kindratenko Control structures in C Lecture Topics Conditional constructs Iterative constructs Examples Style Lecture materials Textbook § 13.3-13.5 Homework None Machine problem MP1.1 due February 2 at 5pm submitted electronically MP1.2 due February 17 at 5pm submitted electronically
Background image of page 1

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

View Full Document Right Arrow Icon
ECE 190 Lecture 05 February 1, 2011 2 V. Kindratenko Conditional constructs In C, conditional constructs can be implemented using if , if-else , or switch statements In the last lecture we covered if and if-else constructs; we will now look at the switch statement switch statement consider example shown in the left column; it also can be implemented as shown on the right: Using cascaded if-else statements Using switch statement if (expression == const1) action1 ; else if (expression == const2) action2 ; else if (expression == const3) action3 ; ... else actionN ; switch (expression) { case const1: action1 ; break ; case const2: action2 ; break ; case const3: action3 ; break ; ... default : actionN ; } this only works when we consider some discrete values to which expression is evaluated, const1, const2 , … action 1 const1 true evaluate expression action 2 const2 true action N . . . false false
Background image of page 2
ECE 190 Lecture 05 February 1, 2011 3 V. Kindratenko Iterative constructs Iterative construct means that some statements will be executed multiple times until some condition is met: Such construct implements a loop structure in which action is executed multiple times, as long as some condition is true o action is also called loop body In C, iterative constructs can be implemented using while , do-while , or for loop statements while and do-while statements while (condition) { subtask ; } do { subtask } while
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

lecture_05 - ECE 190 Lecture 05 February 1 2011 Control...

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

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