lecture_15 - ECE 190 Lecture 15 October 11, 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 15 October 11, 2011 1 V. Kindratenko Control structures in C Lecture Topics Conditional constructs Iterative constructs Examples Style Lecture materials Textbook § 13.3-13.6 Homework/Projects Announcements
Background image of page 1

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

View Full DocumentRight Arrow Icon
ECE 190 Lecture 15 October 11, 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 15 October 11, 2011 3 V. Kindratenko Iterative constructs Iterative construct means that some statements will be executed multiple times until some condition is met: ; LC-3 implementation LOOP ; generate condition code BR(nzp) FALSE ; ; action ; BRnzp LOOP ; FALSE ; 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 DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/24/2012 for the course ECE 190 taught by Professor Hutchinson during the Spring '08 term at University of Illinois, Urbana Champaign.

Page1 / 8

lecture_15 - ECE 190 Lecture 15 October 11, 2011 Control...

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

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