The if statement is used to execute code with condition. If the value of the condition is True then execute the statement else execute another statement or simply end the execution.
There are three combination of the If statement namely:
Execute the code if the condition is true.
The first syntax is used if only one line of code is to be executed after the condition.
The second syntax is used to execute multiple lines of code.
Consider the following example for the first syntax:
The above code will execute only if the condition is true. The If…Else statement is able to execute another statement if the condition is false.
The sample below will output the correct month if the condition is false:
The function date with “F” parameter will simply output the month in full textual representation like January or February.
Take note that in order to execute multiple statements you must enclosed it with curly braces.
Use this statement if you need more condition aside from single condition.
The example code below will try to execute the next condition if the first condition is false. Otherwise execute the statement in the “else” statement.
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.