Skip to content

Commit 9738887

Browse files
authored
Merge pull request #5278 from Rageking8/augment-c6296-warning-reference
Augment C6296 warning reference
2 parents 7c5a478 + 81b91c0 commit 9738887

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

docs/code-quality/c6296.md

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,35 @@
11
---
2-
description: "Learn more about: Warning C6296"
32
title: Warning C6296
4-
ms.date: 11/04/2016
3+
description: "Learn more about: Warning C6296"
4+
ms.date: 03/30/2025
55
f1_keywords: ["C6296", "LOOP_ONLY_EXECUTED_ONCE", "__WARNING_LOOP_ONLY_EXECUTED_ONCE"]
66
helpviewer_keywords: ["C6296"]
7-
ms.assetid: 226573e0-db18-4c44-8fc6-0bc09d1028bc
87
---
98
# Warning C6296
109

11-
> Ill-defined for-loop: Loop body only executed once
10+
> Ill-defined for-loop. Loop body only executed once.
1211
1312
## Remarks
1413

15-
This warning indicates that a for-loop might not function as intended. When the index is unsigned and a loop counts down from zero, its body is run only once.
14+
This warning indicates that a for-loop might unintentionally execute only once. A loop with an unsigned index counting down from zero or a mistaken use of `==` might cause this warning.
1615

1716
Code analysis name: `LOOP_ONLY_EXECUTED_ONCE`
1817

1918
## Example
2019

21-
The following code generates this warning:
20+
The following example generates C6296. Each for-loop shown executes exactly once.
2221

2322
```cpp
24-
void f( )
23+
int main()
2524
{
26-
unsigned int i;
25+
for (unsigned int i = 0; i < 10; i--) {} // C6296
26+
// Use the following line to resolve the warning:
27+
// for (unsigned int i = 0; i < 10; i++) {}
2728

28-
for (i = 0; i < 100; i--)
29-
{
30-
// code ...
31-
}
32-
}
33-
```
29+
for (int i = 0; i == 0; i++) {} // C6296
3430

35-
To correct this warning, use the following code:
36-
37-
```cpp
38-
void f( )
39-
{
40-
unsigned int i;
31+
for (int i = 0; i < 1; i++) {} // OK
4132

42-
for (i = 0; i < 100; i++)
43-
{
44-
// code ...
45-
}
33+
for (int i = 1; i > 0; i--) {} // OK
4634
}
4735
```

0 commit comments

Comments
 (0)