Branching Flashcards
if statements,
The most basic branching structure is an if structure. This instructs the computer to only execute a set of
instructions if a certain condition is true.
if (condition)
{
…instructions…
}
if-else statements,
Branching structures can become more complex by adding an else structure. This follows the if structure
and instructs the computer to execute a set of instructions if the condition is not true. Again, it must
include opening and closing braces {}.
if (condition)
{
…instructions…
}
else
{
…instructions…
}
if-else if-else statements,
Branching structures can also include additional conditions as else if sections. This follows the if structure
but precedes the else structure, and instructs the computer to execute a set of instructions if these
additional conditions are true. Each additional condition must include opening and closing braces {}.
if (condition)
{
…instructions…
}
else if (condition)
{
…instructions…
}
else
{
…instructions…
}
nested statements
A nested if statement is an if statement placed inside another if statement.
if (condition)
{
if (condition)
{
sfhahiugeigr
}
else eiawgurgauigbaiwbrgj
}