Lecture23 - ComputerProgrammingITAC162. Todays Agenda...

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 2006 Today’s Agenda Control Structure Conditional If statement Switch statement Conditional operator statement Iteration for while do-while Examples Morning class
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 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
Background image of page 2
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
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 2006 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/14/2010 for the course CS SS ZG653 taught by Professor Shanta during the Spring '09 term at Birla Institute of Technology & Science.

Page1 / 15

Lecture23 - ComputerProgrammingITAC162. Todays Agenda...

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