C++ examples for Statement:do while
Using a do-while loop to count characters
#include <iostream> int main()/*w w w .ja v a 2 s . c om*/ { long count {}; char ch {}; std::cout << "Please enter a sequence of characters terminated by '#':" << std::endl; do { std::cin >> ch; ++count; } while (ch != '#'); // do not count '#' as a character --count; std::cout << "You entered characters (not counting spaces and the terminal #)." << std::endl; }