
The if() condition allows branching of program codes based on a condition. The general structure looks like this:
if(condition)We can also nest (put) if() conditions within another if() conditions to form complex logic for our programs. Do take care of the curly brackets, and always use tabs to indent the statements properly to aid debugging.
{
// Write statements to do if condition is true
}
else
{
// Write statements to do if condition is false
}
Things to note about if() conditions:
- an if() can have one and only one else or not at all
- a else must come with a if()
- if() conditions are independent of each other
No comments:
Post a Comment