Fixed the formatting in all blocks of code (#34095)

* Fixed the formatting in all blocks of code

* Update index.md
This commit is contained in:
Descritorio
2019-03-31 13:57:02 -05:00
committed by The Coding Aviator
parent 5810a2cf41
commit d03f332de5

View File

@ -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,23 +23,21 @@ Do something first and then test if we have to continue. The result is that the
```cpp
#include <iostream.h>
using namespace std;
#include <iostream>
using namespace std;
int main()
{
int main()
{
int counter, howmuch;
cin >> howmuch;
counter = 0;
do
{
do {
counter++;
cout << counter << '\n';
}
while ( counter < howmuch);
} 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.