The if Statement
if ( condition )
{ do this if true }
else
{ do this if false }
- False is zero. A string that is empty or holds a single zero is false.
- Yes, you can nest.
- Yes, you want the curly braces.
- Yes, you should indent, at least if you want to remain sane (and pass the course).
- See the examples under perl/ifdir.
Alternative Approach
- command && commandT
- command || commandF
- If the command is successful, commandT is executed.
- If the command is not successful, commandF is executed.
- Limited use.