Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Declaração If | Introduction to Conditional Statements
course content

Conteúdo do Curso

C++ Conditional Statements

Declaração IfDeclaração If

A instrução if é um componente fundamental de fluxo de controle na maioria das linguagens de programação. Ela permite que um programa faça decisões e execute diferentes blocos de código baseados em se uma determinada condição é verdadeira ou falsa. A ideia por trás das instruções if é simples: Se uma condição for atendida, faça algo, caso contrário, não faça.

Here is the if statement syntax:

Aqui está a sintaxe da instrução if:

cpp

main.cpp

If you have an if statement with only one statement to be executed when the condition is true, you can omit the curly braces { }. For example:

same as

Se você possui uma estrutura de condição if com apenas uma instrução a ser executada quando a condição é verdadeira, você pode omitir as chaves { }. Por exemplo:

Note

The condition within an if statement requires a bool type. As you may be aware from C++ Data Types course, you can obtain a bool type by performing complex operations using || (logical OR) and && (logical AND). Therefore, the condition in an if statement can also consist of these complex operations.

Tarefa

  • Check if a two dimensional square with x (length) and y (height) can fit into another square with dimensions x1 (length) and y1 (height).
  • Output Can fit in console if it can.

Tudo estava claro?

Seção 1. Capítulo 3
toggle bottom row
course content

Conteúdo do Curso

C++ Conditional Statements

Declaração IfDeclaração If

A instrução if é um componente fundamental de fluxo de controle na maioria das linguagens de programação. Ela permite que um programa faça decisões e execute diferentes blocos de código baseados em se uma determinada condição é verdadeira ou falsa. A ideia por trás das instruções if é simples: Se uma condição for atendida, faça algo, caso contrário, não faça.

Here is the if statement syntax:

Aqui está a sintaxe da instrução if:

cpp

main.cpp

If you have an if statement with only one statement to be executed when the condition is true, you can omit the curly braces { }. For example:

same as

Se você possui uma estrutura de condição if com apenas uma instrução a ser executada quando a condição é verdadeira, você pode omitir as chaves { }. Por exemplo:

Note

The condition within an if statement requires a bool type. As you may be aware from C++ Data Types course, you can obtain a bool type by performing complex operations using || (logical OR) and && (logical AND). Therefore, the condition in an if statement can also consist of these complex operations.

Tarefa

  • Check if a two dimensional square with x (length) and y (height) can fit into another square with dimensions x1 (length) and y1 (height).
  • Output Can fit in console if it can.

Tudo estava claro?

Seção 1. Capítulo 3
toggle bottom row
some-alt