{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Lecture23 - Todays Agenda Control Structure Conditional If...

This preview shows pages 1–5. Sign up to view the full content.

1 Computer Programming I TA C162 . 01 Mar 2006 Today’s Agenda Control Structure Conditional If statement Switch statement Conditional operator statement Iteration for while do-while Examples Morning class

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

View Full Document
2 Computer Programming I TA C162 . 01 Mar 2006 If Statement if (condition) { statement-block; } next-statement; condition Statement -block T F Condition is a C expression, which evaluates to TRUE (non-zero) or FALSE (zero). Statement-Block may be a single statement Similar to BR instruction in LC-3
3 Computer Programming I TA C162 . 01 Mar 2006 Example If Statements if (x <= 10) y = x * x + 5; if (x <= 10) { y = x * x + 5; z = (2 * y) / 3; } if (x <= 10) y = x * x + 5; z = (2 * y) / 3; compound statement; both executed if x <= 10 only first statement is conditional second statement is always executed

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

View Full Document
4 Computer Programming I TA C162 . 01 Mar 2006 More If Examples if (0 <= age && age <= 11) kids += 1; if (month == 4 || month == 6 ||month == 9 || month == 11) printf(“The month has 30 days.\n”); if (x = 2) y = 5; This is a common programming error (= instead of ==), not caught by compiler because it’s syntactically correct.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 15

Lecture23 - Todays Agenda Control Structure Conditional If...

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

View Full Document
Ask a homework question - tutors are online