Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara If Expression | Conditional Statements
Introduction to C++
course content

Contenuti del Corso

Introduction to C++

Introduction to C++

1. Basics
2. Variables
3. Conditional Statements
4. Loops
5. Intro to Arrays

book
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 or IF) will cause an error.

question-icon

Accept the variables x and y as the input of the user. Compare the variables, and print the message “x is equal to y” if they are equal:

cin >> x;
cin >> y;
if
{
    
"x is equal to y";
}

Click or drag`n`drop items and fill in the blanks

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 3. Capitolo 2

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

course content

Contenuti del Corso

Introduction to C++

Introduction to C++

1. Basics
2. Variables
3. Conditional Statements
4. Loops
5. Intro to Arrays

book
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 or IF) will cause an error.

question-icon

Accept the variables x and y as the input of the user. Compare the variables, and print the message “x is equal to y” if they are equal:

cin >> x;
cin >> y;
if
{
    
"x is equal to y";
}

Click or drag`n`drop items and fill in the blanks

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 3. Capitolo 2
some-alt