IF, THEN, ELSE
With most programming structures there will come a time where you need to loop through the commands you’ve entered to create better functionality, and ultimately a better program.
STEP 1
Let’s look at the If, Then and Else statements now, which when executed correctly, compare a set of instructions and simply work out that IF something is present, THEN do something, ELSE do something different. Create a new script called greeting2.sh and enter the text in the screenshot below into it.
STEP 2
Greeting2.sh is a copy of greeting.sh but with a slight difference. Here we’ve added a loop starting at the if statement. This means, IF the variable entered is equal to David the next line, THEN, is the reaction to what happens, in this case…
