A do-while loop is an exit-controlled loop. The statements inside the loop body are executed first, and the condition is tested at the bottom. This ensures that the code executes at least once, regardless of whether the condition is initially true or false.
#include <iostream>
int main() {
int choice = 0;
do {
std::cout << "\n============================\n";
std::cout << " Veewom Banking Portal \n";
std::cout << "============================\n";
std::cout << "1. Check Account Balance\n";
std::cout << "2. Deposit Funds\n";
std::cout << "3. Withdraw Cash\n";
std::cout << "4. Exit Application\n";
std::cout << "Enter your choice (1-4): ";
std::cin >> choice;
switch (choice) {
case 1: std::cout << "Your current balance is: $15,400.00\n"; break;
case 2: std::cout << "Deposit initiated successfully.\n"; break;
case 3: std::cout << "Withdrawal completed safely.\n"; break;
case 4: std::cout << "Thank you for using Veewom Banking!\n"; break;
default: std::cout << "Invalid choice! Please select 1-4.\n"; break;
}
} while (choice != 4);
return 0;
}
Boost your C++ proficiency by studying these closely connected core modules:
Compare entry vs exit control mechanisms.
Handling menu options inside a do-while loop.
Fixed-range iteration counters.