The "if" Statement
You can use the if statement to conditionally execute part of your program, based on the truth value of a given expression. Here is the general form of an if statement:
If test evaluates to true, then then-statement is executed and else-statement is not. If test evaluates to false, then else-statement is executed and then-statement is not. The else clause is optional. Here is an actual example:
If x == 10 evaluates to true, then the statement message("x is 10"); is executed. If x == 10 evaluates to false, then the statement message("x is 10"); is not executed.
Here is an example using else:
You can use a series of if statements to test for multiple conditions:
This function calculates and displays the date of Easter for the given year y:
Last updated
Was this helpful?