If Statements
An if statement is a conditional statement that is used to execute code based on a condition. The syntax for an if statement is as follows:
if (condition) {
// code to be executed if condition is true
}
The condition is a Boolean expression that evaluates to either true or false. If the condition is true, the code inside the if statement will be executed. If the condition is false, the code inside the if statement will be skipped.
Here is an example of an if statement:
In this example, the condition is x > 5. If the value of x is greater than 5, the code inside the if statement will be executed. Otherwise, the code inside the if statement will be skipped.
Task
Run the above code and experiment with the code to get used to it.