From d03f332de51c035ac200a4bb1dd371e1b20db13a Mon Sep 17 00:00:00 2001 From: Descritorio <36520867+Descritorio@users.noreply.github.com> Date: Sun, 31 Mar 2019 13:57:02 -0500 Subject: [PATCH] Fixed the formatting in all blocks of code (#34095) * Fixed the formatting in all blocks of code * Update index.md --- .../english/cplusplus/do-while-loop/index.md | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/guide/english/cplusplus/do-while-loop/index.md b/guide/english/cplusplus/do-while-loop/index.md index 55ed36da7d..37df6da551 100644 --- a/guide/english/cplusplus/do-while-loop/index.md +++ b/guide/english/cplusplus/do-while-loop/index.md @@ -6,8 +6,7 @@ This is just like the `while` and `for` loop but the only difference is that the The `do while` loop has the following form: ```cpp -do -{ +do { // do something; } while(condition); @@ -24,34 +23,32 @@ Do something first and then test if we have to continue. The result is that the ```cpp -#include - using namespace std; +#include +using namespace std; - int main() - { - int counter, howmuch; +int main() +{ + int counter, howmuch; - cin >> howmuch; - counter = 0; - do - { - counter++; - cout << counter << '\n'; - } - while ( counter < howmuch); - return 0; - } + cin >> howmuch; + counter = 0; + do { + counter++; + cout << counter << '\n'; + } while (counter < howmuch); + return 0; +} ``` A common mistake with do-while loops is attempting to use a variable that is local to the loop in the conditional statement. This will result in a compilation error because the local variable is not in the correct scope for the conditional statement to use it. Be sure to declare any conditional variables outside of the do while loop. ```cpp int main() { - do { - // This will not compile because the counter is in the scope of the do, whereas the while conditional is outside. - int counter = 10; - } while (counter < 10); - return 0; + do { + // This will not compile because the counter is in the scope of the do, whereas the while conditional is outside. + int counter = 10; + } while (counter < 10); + return 0; } ```