Conteúdo do Curso
Introduction to C++
Introduction to C++
If Expression
To perform different actions depending on the different decisions we can use already mentioned logical operators and the conditional statement if
.
if
executes the block of code if the condition is true. In C++, it's implemented as follows:
For example, we know how to check if the variable x
is greater than y
. Let’s write the message (with the statemant if
) if this condition is true (x
is bigger than y
):
As x
is 7, and y
is 5, x
is greater than y
, so our condition is true and the code will print the message "x is bigger than y"
.
The statement
if
is case sensitive. It means that usage of uppercase letters (If
orIF
) will cause an error.
Obrigado pelo seu feedback!