{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

conditionals - Conditionals Darin Brezeale The University...

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

View Full Document Right Arrow Icon
Conditionals Darin Brezeale The University of Texas at Arlington Conditionals – p.1/22
Background image of page 1

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

View Full Document Right Arrow Icon
Basic Concepts – Conditionals Conditionals are used for making decisions. The conditionals available in C are if and if-else statements the switch statement the conditional expression operator, ?: Conditionals – p.2/22
Background image of page 2
Operators – Relational The following relational operators are available in C: == equality != not equal < less than > greater than <= less than or equal to >= greater than or equal to Conditionals – p.3/22
Background image of page 3

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

View Full Document Right Arrow Icon
Conditionals – if The basic format of the if statement is if (condition_is_true) do_something; Examples if (x >= 2) y = 10; if (y == 10) printf("y is now 10"); Conditionals – p.4/22
Background image of page 4
Conditionals – if cont. Question: What if we want to do more than one thing in response to a condition being true? Answer: Create a block of statements. Example if (x >= 2) { y = 10; printf("y is now 10"); } Conditionals – p.5/22
Background image of page 5

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

View Full Document Right Arrow Icon
Conditionals – if cont. What if we wish to have a second conditional statement in response to the first condition being true? We can nest the if statements. Example if (count > 23) if(time < 45) z = 56; This assigns a value of 56 to z only if count > 23 and time < 45 . Conditionals – p.6/22
Background image of page 6
Conditionals – if-else Sometimes we wish to do one thing if a condition is true but another if the condition is false. For this we
Background image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}