Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to define the cyclic variable ​ in C++

Shulou Source: shulou.com Published: 2022-06-01 19:30:08 10月02日 Update

This article mainly introduces "how to define cyclic variables in C++". In daily operation, I believe many people have doubts about how to define cyclic variables in C++. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubt of "how to define cyclic variables in C++". Next, please follow the editor to study!

ES.74: try to define loop variables in loop variable initialization expressions

Reason (reason)

Limit the loop variable visibility to the scope of the loop. Avoid using the loop variable for other purposes after the loop.

Limits the scope of the loop variable to the loop. Avoid using loop variables for other purposes after a loop.

Example (sample)

For (int I = 0; I

< 100; ++i) { // GOOD: i var is visible only inside the loop // ... } Example, don't(反面示例) int j; // BAD: j is visible outside the loop for (j = 0; j < 100; ++j) { // ... } // j is still visible here and isn't needed See also: Don't use a variable for two unrelated purposes 参见:不用将变量用于两个不同的目的。 Example(示例) for (string s; cin >

> s;) {

Cout

Tags: Loop variable Clearing Learning example Code Action Loop body more purpose help restriction different practical necessary next not two reason Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information OPPO Reno MySQL Huawei Microsoft