{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

conditionals

# conditionals - Conditionals Darin Brezeale The University...

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

Conditionals Darin Brezeale The University of Texas at Arlington Conditionals – p.1/22

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}