answersLogoWhite

0

The do while loop is useful for the special loops that they must circulate at least one time.

#include <iostream>

using namespace std;

int main()

{

int num,digit;

cout<<"Enter a #\n";

cin>>num;

cout<<"Invers is : ";

do

{

digit=num/10;

cout<<digit;

num/=10;

} while(num != 0);

return 0;

}

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao
JudyJudy
Simplicity is my specialty.
Chat with Judy
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
More answers

//do while example

#include<stdio.h>

int main(void)

{

const int SECRET_CODE = 15;

int code;

do{

printf("Type the secret code number to enter.\n");

scanf("%d", &code);

}while(code!=SECRET_CODE);

printf("Well done , you can now enter\n");

return 0;

}

#include <stdio.h>

main()

{

int i = 10;

do

{

printf("Hello %d\n", i );

i = i -1;

}while ( i > 0 );

}

/*break in do while*/

#include <stdio.h>

main()

{

int i = 10;

do

{

printf("Hello %d\n", i );

i = i -1;

if( i == 6 )

{ break;

}

}while ( i > 0 );

}

User Avatar

Wiki User

14y ago
User Avatar

#include<iostream>

int main()

{

// Count from 1 to 10 using do-while loop.

int i=0;

do

{

std::cout<<++i<<std::endl;

}while i<10);

// Note: i is 10 at this point...

}

User Avatar

Wiki User

11y ago
User Avatar

Unlike the while() loop, a do..while() loop always executes at least once. Iteration is dependant on the conditional expression which is evaluated at the end of the loop, whereas a while() loop's conditional expression is evaluated before entering the loop, and may never execute. for() loops are also evaluated before entering the loop, but the conditional expression is optional.

User Avatar

Wiki User

13y ago
User Avatar

int main (int argc, char **argv)
{
int i;

i= -1;
while (++i < argc) printf ("%d. '%s'\n", i, argv[i]);
}

User Avatar

Wiki User

15y ago
User Avatar

usable

do statement while (expression);

User Avatar

Wiki User

14y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Do while in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp