1402 22 - 3/28/2010 1 COMP 1002/1402 Introduction to...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: 3/28/2010 1 COMP 1002/1402 Introduction to Systems Programming Chapter 22: Odds and Ends Conditional Expressions if (expression) statement1 else statement2 If Else: expression ? expression1 : expression2 ; COMP1002/1402 - Chapter 22: Odds and Ends 2 Alternate two way logic: 3/28/2010 2 Conditional Expression Example If else method: Conditional expression: If(a<10) a++; else a--; a<10 ? a++ : a--; COMP1002/1402 - Chapter 22: Odds and Ends 3 Conditional Expressions Although you can nest conditional expressions, it is NOT recommended. A good alternative to one if else statement (often shortens code). COMP1002/1402 - Chapter 22: Odds and Ends 4 3/28/2010 3 Conditional Expression Example 2 Suppose you have a flag to decide if your program will output to a file or to the monitor (called fileFla ) will output to a file or to the monitor (called fileFlag ). When printing to the monitor, you want to output 20 numbers per line. When printing to a file, you want to output 30 numbers per line. A variable numPerLine will contain how many numbers to print or output per line....
View Full Document

Page1 / 11

1402 22 - 3/28/2010 1 COMP 1002/1402 Introduction to...

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

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