conditional statements intro Flashcards
0
means false
true
is defined as all other non-zero values
if/else syntax
if(boolean expression)
{
}
else
{
}
else if structure
else if(boolean expression)
{
{
else if()
allows one to be specific if the first (if) condition fails
*only executes if the previous condition fails
ternary operator syntax
condition ? expression_if_true: expression_if_false;
short circuiting
when the compiler skips evaluation of further conditions when possible
*possible when evaluating logical or/and
*best practice to write code that allows for this
one line if-else statements
refers to the code executed by the if-else statements
*other code will be interpreted as outside the if-else statement
correct:
if()
printf();
else
printf();
incorrect:
if()
printf();
printf();
else()
printf();