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:
committed by
The Coding Aviator
parent
5810a2cf41
commit
d03f332de5
@ -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:
|
The `do while` loop has the following form:
|
||||||
```cpp
|
```cpp
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
// do something;
|
// do something;
|
||||||
} while(condition);
|
} while(condition);
|
||||||
|
|
||||||
@ -24,23 +23,21 @@ Do something first and then test if we have to continue. The result is that the
|
|||||||
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
#include <iostream.h>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int counter, howmuch;
|
int counter, howmuch;
|
||||||
|
|
||||||
cin >> howmuch;
|
cin >> howmuch;
|
||||||
counter = 0;
|
counter = 0;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
counter++;
|
counter++;
|
||||||
cout << counter << '\n';
|
cout << counter << '\n';
|
||||||
}
|
} while (counter < howmuch);
|
||||||
while ( counter < howmuch);
|
|
||||||
return 0;
|
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.
|
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.
|
||||||
|
Reference in New Issue
Block a user