Skip to content

Commit 23f3b3c

Browse files
TylerMSFTTylerMSFT
authored andcommitted
acrolinx
1 parent 5669355 commit 23f3b3c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ helpviewer_keywords: ["if keyword [C++]", "else keyword [C++]"]
77
---
88
# if-else statement (C++)
99

10-
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.
10+
An if-else statement controls conditional branching. Statements in the *`if-branch`* are executed only if the *`condition`* evaluates to a nonzero 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.
1111

12-
*`condition`* expressions that evaluate to non-zero are:
12+
*`condition`* expressions that evaluate to nonzero are:
1313

1414
- **`true`**
1515
- a non-null pointer,
16-
- any non-zero arithmetic value, or
16+
- any nonzero arithmetic value, or
1717
- a class type that defines an unambiguous conversion to an arithmetic, boolean, or pointer type. (For information about conversions, see [Standard Conversions](../cpp/standard-conversions.md).)
1818

1919
## Syntax
@@ -109,7 +109,7 @@ x < 11 is true!
109109

110110
## <a name="if_with_init"></a> if statement with an initializer
111111

112-
Starting in C++17, an **`if`** statement may also contain an *`init-statement`* expression that declares and initializes a named variable. Use this form of the if-statement when the variable is only needed within the scope of the if-statement. **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.
112+
Starting in C++17, an **`if`** statement might also contain an *`init-statement`* expression that declares and initializes a named variable. Use this form of the if-statement when the variable is only needed within the scope of the if-statement. **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.
113113

114114
### Example
115115

@@ -201,9 +201,9 @@ int main()
201201
}
202202
```
203203
204-
The **`if constexpr`** statement is evaluated at compile time, and the compiler only generates code for the **`if`** branch that matches the type of the argument sent to the function template. If you comment out the **`if constexpr`** statement and uncomment the **`if`** statement, the compiler generates code for both branches. That means you'll get an error:
205-
- If you call `ShowValue(a);` you'll get an error on `return *t` because `t` is not a pointer, even though the **`if`** statement is false and the code is never executed.
206-
- If you call `ShowValue(pB);` you'll get an error on `return t` because `t` is a pointer, even though the **`if`** statement is true and the code is never executed.
204+
The **`if constexpr`** statement is evaluated at compile time, and the compiler only generates code for the **`if`** branch that matches the type of the argument sent to the function template. If you comment out the **`if constexpr`** statement and uncomment the **`if`** statement, the compiler generates code for both branches. That means you get an error:
205+
- If you call `ShowValue(a);` you get an error on `return *t` because `t` isn't a pointer, even though the **`if`** statement is false and the code is never executed.
206+
- If you call `ShowValue(pB);` you get an error on `return t` because `t` is a pointer, even though the **`if`** statement is true and the code is never executed.
207207
208208
Using `if constexpr` solves this problem because only the statement that matches the type of the argument sent to the function template is compiled.
209209

0 commit comments

Comments
 (0)