In its most basic form, the if command defines statements that will be evaluated to be true or false. Whether they are true or not depends on the specific conditions the statement describes. If these conditions are true, code will be run. If they are not true, they are ignored and processing moves on to the next statement.
The else command expands on this structure and allows the program to choose between two or more blocks of code to execute when the condition if describes is false. The condition is evaluated, and if it is true it is executed, and if it is false the alternative else command is run.
Broken down in coding language it looks as such:
If (a specific condition is true) {
This happens
}
else{
if the above statement is false than this happens
}
The if/else commands are your basic true or false questions. The important thing to remember is that under different conditions, different things happen. These if/else commands are present in everyday life in basic ways we rarely think about but are easy to relate to. Each morning we get dressed. If it is sunny out we will wear a bathing suit, shorts, a shirt and jandals. If it is not sunny out we will wear something else such as jeans and a sweater. The commands can get deeper and more nested just as our decisions often get more complex. If it is sunny out but we are going to uni, we would not wear our bathing suit. Instead we might wear a dress. If it is sunny out but we are going to workout, we would wear shorts and a singlet. If it is raining out this would be a whole other condition, so a new combination of ifs would be nested in the else commands of the if (it is sunny) condition. Because if it were raining you would wear something different to uni, to workout or to hangout. Through outfits, symbols and sounds to represent dress and weather, I’ve done my best to create a real life association with the if/else processing commands.