Lec22 - Computer Programming I TA C162. Next Step. Control...

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

View Full Document Right Arrow Icon
1 Computer Programming I TA C162 . 01 Mar 2007 Next Step… Control Structure Conditional If statement Switch statement Conditional operator statement Iteration for while do-while Examples Today’s Menu
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Computer Programming I TA C162 . 01 Mar 2007 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 can be a single statement Similar to BR instruction in LC-3
Background image of page 2
3 Computer Programming I TA C162 . 01 Mar 2007 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
Background image of page 3

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

View Full DocumentRight Arrow Icon
Computer Programming I TA C162 . 01 Mar 2007 More If Examples 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 ==),
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/07/2010 for the course CS&IS TA C162 taught by Professor Kavitha during the Spring '09 term at Birla Institute of Technology & Science.

Page1 / 15

Lec22 - Computer Programming I TA C162. Next Step. Control...

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

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