lec4-c - ECE 175 ECE 175 Fall 2007 2 if(expression commands...

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

View Full Document Right Arrow Icon
ECE 175
Background image of page 1

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

View Full DocumentRight Arrow Icon
05/11/09 ECE 175, Fall 2007 2
Background image of page 2
05/11/09 ECE 175, Fall 2007 3 if (expression){ commands} else { commands} Examples { i = j; j = 10; } printf(“Input accepted”); else printf(“You pressed the wrong button”);
Background image of page 3

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

View Full DocumentRight Arrow Icon
Any time a binary (true/false) condition has to be checked you can use the if command 05/11/09 ECE 175, Fall 2007 4 If(condi tion) true false input
Background image of page 4
05/11/09 ECE 175, Fall 2007 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
05/11/09 ECE 175, Fall 2007 6 if (expression) { commands } else if (expression) { commands } else if (expression) { commands } ... else { commands }
Background image of page 6
Any time multiple conditions have to be checked for the same input 05/11/09 ECE 175, Fall 2007 7 input cond 1 cond 2 cond 3 cond n
Background image of page 7

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

View Full DocumentRight Arrow Icon
05/11/09 ECE 175, Fall 2007 8
Background image of page 8
05/11/09 ECE 175, Fall 2007 9
Background image of page 9

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

View Full DocumentRight Arrow Icon
05/11/09 ECE 175, Fall 2007 10 switch (variable){ case value: commands break; case value: commands break; ... default: commands } break; Stops the execution of the loop Required in the switch command, cause otherwise the default will be executed as well
Background image of page 10
Any time multiple conditions have to be checked for the same input but the conditions are either integers or characters Only equality conditions are checked 05/11/09 ECE 175, Fall 2007 11 input case 1 case 2 case 3 default
Background image of page 11

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

View Full DocumentRight Arrow Icon
The if statement is more general than switch statement Case labels can contain only integer or char values Double, float and string values not permitted Programming practice Use switch statements when label contains a reasonable number of integer(char) values Use default label whenever possible 05/11/09 ECE 175, Fall 2007 12
Background image of page 12
05/11/09 ECE 175, Fall 2007 13 switch (var){ case value1: commands break; case value2: commands break; ... default: commands } if (var == value1) { commands } else if(var ==value2) { commands } ... else { commands }
Background image of page 13

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

View Full DocumentRight Arrow Icon
If statements can exist nested within other if statements or any other condition or loop statements (such as while, for, or do-while) 05/11/09 ECE 175, Fall 2007 14
Background image of page 14
scanf in general ignores any spaces, tabs, newlines Caution: when scanf waits for a char it will read spaces and newlines You have to be cautious when you read single characters! 05/11/09
Background image of page 15

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

View Full DocumentRight Arrow Icon
Image of page 16
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/06/2008 for the course ECE 175 taught by Professor Grubbs during the Fall '08 term at Arizona.

Page1 / 34

lec4-c - ECE 175 ECE 175 Fall 2007 2 if(expression commands...

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

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