Talk:Control Structures
Using else we can have a code block which executes when the if statement evaluates to true, and another code block which executes when the if statement evaluates to false.
if(false)
{
print("this line never gets printed");
}
else
{
print("this line gets printed");
}
We also need to understand nesting if statements.
if(true)
{
if(true)
{
print("this line gets printed");
}
else
{
print("this line never gets printed");
}
print("this line gets printed also");
}
if(false)
{
if(true)
{
print("this line never gets printed");
//though inside an if(true) statement,
//the outer if(false) stops the code from ever getting here.
}
else
{
print("this line never gets printed");
}
print("this line never gets printed");
}
Now you only need to put it all together as needed for your situation.