Skip to content

Commit b37dd39

Browse files
author
Colin Robertson
committed
Fix warnings in if-else
1 parent e7a5b56 commit b37dd39

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

docs/cpp/if-else-statement-cpp.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
---
2-
title: "if-else Statement (C++)"
3-
description: "The if-else, if-else with initializer, and if-constexpr statements in the C++ programming language."
2+
title: "if-else statement (C++)"
3+
description: "Use if-else, if-else with initializer, and if-constexpr statements to control conditional branching."
44
ms.date: 10/02/2020
5-
description: "Use if-else statements in C++ to control conditional branching."
65
f1_keywords: ["else_cpp", "if_cpp"]
76
helpviewer_keywords: ["if keyword [C++]", "else keyword [C++]"]
87
ms.assetid: f8c45cde-6bce-42ae-81db-426b3dbd4caa
98
---
10-
# if-else Statement (C++)
9+
# if-else statement (C++)
1110

1211
An if-else statement controls conditional branching. Statements in the *`if-branch`* are executed only if the *`condition`* evaluates to a non-zero value (or **`true`**). If the value of *`condition`* is nonzero, the following statement gets executed, and the statement following the optional **`else`** gets skipped. Otherwise, the following statement gets skipped, and if there's an **`else`** then the statement following the **`else`** gets executed.
1312

@@ -52,9 +51,15 @@ An if-else statement controls conditional branching. Statements in the *`if-bran
5251
&emsp; **`if`** **`constexpr`**<sub>*opt*</sub><sup>17</sup> **`(`** *`init-statement`*<sub>*opt*</sub><sup>17</sup> *`condition`* **`)`** *`if-branch`*\
5352
&emsp; **`if`** **`constexpr`**<sub>*opt*</sub><sup>17</sup> **`(`** *`init-statement`*<sub>*opt*</sub><sup>17</sup> *`condition`* **`)`** *`if-branch`* **`else`** *`else-branch`*
5453

55-
<sup>17</sup> This element is available starting in C++17.
54+
<sup>17</sup> This optional element is available starting in C++17.
5655

57-
## Example if-else statements
56+
## if-else statements
57+
58+
In all forms of the **`if`** statement, *`condition`*, which can have any value except a structure, is evaluated, including all side effects. Control passes from the **`if`** statement to the next statement in the program unless the executed *`if-branch`* or *`else-branch`* contains a [`break`](../cpp/break-statement-cpp.md), [`continue`](../cpp/continue-statement-cpp.md), or [`goto`](../cpp/goto-statement-cpp.md).
59+
60+
The **`else`** clause of an `if...else` statement is associated with the closest previous **`if`** statement in the same scope that does not have a corresponding **`else`** statement.
61+
62+
### Example
5863

5964
This sample code shows several **`if`** statements in use, both with and without **`else`**:
6065

@@ -151,10 +156,6 @@ int main()
151156
}
152157
```
153158

154-
In all forms of the **`if`** statement, *`condition`*, which can have any value except a structure, is evaluated, including all side effects. Control passes from the **`if`** statement to the next statement in the program unless the executed *`if-branch`* or *`else-branch`* contains a [`break`](../cpp/break-statement-cpp.md), [`continue`](../cpp/continue-statement-cpp.md), or [`goto`](../cpp/goto-statement-cpp.md).
155-
156-
The **`else`** clause of an `if...else` statement is associated with the closest previous **`if`** statement in the same scope that does not have a corresponding **`else`** statement.
157-
158159
## <a name="if_constexpr"> if constexpr statements
159160

160161
Starting in C++17, you can use an **`if constexpr`** statement in function templates to make compile-time branching decisions without having to resort to multiple function overloads. **Microsoft-specific**: This form is available starting in Visual Studio 2017 version 15.3, and requires at least the [`/std:c++17`](../build/reference/std-specify-language-standard-version.md) compiler option.

0 commit comments

Comments
 (0)