other conditional methods. conditional operator conditional operator (?:) conditional operator ( ?:...

Download Other Conditional Methods. Conditional Operator Conditional Operator (?:) Conditional operator ( ?: ) – Ternary operator: 3 arguments expression1 ? expression2

Post on 01-Jan-2016

217 views

Category:

Documents

5 download

Embed Size (px)

TRANSCRIPT

Pathway Introduction: Information Technology

Other Conditional MethodsConditional OperatorConditional Operator (?:)Conditional operator (?:) Ternary operator: 3 argumentsexpression1 ? expression2 : expression3

If expression1 is true, result is expression2false, result is expression33Conditional Operator (?:)Example: int max = (a >= b) ? a : b;

Short for: int max;if (a >= b) max = a;else max = b;4Common UsePick one of two values inside larger expression:

Switch StatementComparing ifelse with ifsMethod 1:if( month == 1) cout

Recommended

View more >