Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how do I use do whiles

+11 votes
asked Mar 6, 2025 by Clarence Napoleon (220 points)

1 Answer

0 votes
answered Mar 7, 2025 by Peter Minarik (101,340 points)
edited Mar 11, 2025 by Peter Minarik

In C/C++, it would look like this:

  1. while (condition) statement
  2. do statement while (condition)

, where condition is any expression that can be evaluated to a boolean (true/false value) and statement is the instruction(s) that needs to be executed as long as the condition evaluates to true. Every time the statement is executed, the condition  is re-evaluated to check if it's still true.

For more details, please visit: https://en.cppreference.com/w/cpp/language/while

Other languages should have similar logic. You should be able to find online references for your language of interest.

You can consider the below "pseudo-code":

#include <stdio.h>

int main()
{
    int money = 100;
    while (money > GetIceCreamPrice())
        money -= GetIceCreamPrice();
    
    do
    {
        money += Work();
    } while (money < GetCarPrice());

    return 0;
}

commented Mar 10, 2025 by cpp guy (1,020 points)
what he said
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...