Lecture 10 - Conditionals and Loops

Lecture 10 - Conditionals and Loops - integer value (not...

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

View Full Document Right Arrow Icon
10 Conditionals and Loops Oct 12, 2006 Annoucements • A1 all marked. • Quiz grades updating soon. • A2 due at noon today. • A3 due Oct 26th at noon (appearing on web-site tomorrow) • Midterm Oct 19th at 5:30pm (locations depend on your last name) Announcements Continued • Appointments link – please us it. Review • Last time we saw a lot of comparative operators, Boolean operators, learned about precedence and order of operations and complicated if conditions Gotchas • if (x==3||4) – order of operations? – equals is done first • if (x==(3||4)) – x==1 • if ((x==3)||4) – always true • if ( (x==3) || (x==4) ) – the correct way More Gotchas • if ( 3<x<5 ) • if ( (3<x)<5 ) – always true – correct
Background image of page 1

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

View Full DocumentRight Arrow Icon
switch – another conditional switch (integer_expression) { case integer_value: instructions; break; case integer_value: instructions; break; } Details • integer_expression can be: – integer variable: x – eqaution that computes and integer – function that returns an integer
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: integer value (not much use) integer_value can be: integer value switch checks an integer value and compares it to a number of cases execution jumps to the case and proceeds until break break moves out of code block { } default case covers other possibilities example: switch.c Missing the break If you forget about the break statement your code just keeps on going through the next case statement and the next, etc. Modied switch.c Programming advice. 1. Put in the basic structure: switch ( integer_expression ) { } 2. add skeleton cases: case integer_value: break; 3. ll in the details Characters as integers Every character is also an integer: can print it using %d or %c ASCII codes intchar.c Loops For repeated actions. while ( boolean_expression ) { code; } No switch for you does not work with oating point number, or strings...
View Full Document

Page1 / 3

Lecture 10 - Conditionals and Loops - integer value (not...

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

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