Now that you know what an if statement is, you can write an actual program using variables and if statements. Create variable A with a value of 12 and an if statement to see if it’s larger than 10. If it is, variable A will be set to 10.
int A = 12; if (A > 10){
A = 10}
Now you can add an else statement, which will be performed if the if statement turns out to be false:
if (condition)
{
//happens if condition is true
}
else
{
//happens if condition is false
}
Create an else statement so A will be set to 1 if it is not larger than 10. Your code should look like this:
int A = 12;
if (A > 10)
{
A = 10;
}
else
{
A = 1;
}