Questions tagged [do-while]

A do while loop, sometimes just called a do loop, is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition.

The do-while loop can be found in most computer languages and can be thought of as a repeating if statement.

The syntax for the while loop for many computer languages is as follows:

do
{
    // loop body
} while (condition);

The do while construct consists of a block of code and a condition. First, the code within the block is executed, and then the condition is evaluated. If the condition is true the code within the block is executed again. This repeats until the condition becomes false.

Because do while loops check the condition after the block is executed, the control structure is often also known as a post-test loop. Contrast with the while loop, which tests the condition before the code within the block is executed.

(excerpted from http://en.wikipedia.org/wiki/Do_while_loop )

2862 questions
0
votes
2 answers

C text game segmentation fault and debugging

I wanted to wrote a simple text game in C. The game generates random 2D position using 2 double variables in range from -10.000 to 10.000 (X, Y) as the "treasure" position. Player begins at position 0.000, 0.000. Then the game asks the player which…
jirick
  • 71
  • 6
0
votes
1 answer

Unhandled exception at 0x53918F0E (ucrtbased.dll)

**#include #include void buildArray(); int main(void) { int example[20]; buildArray(example); getch(); } void buildArray(int param[]) { int i = 0; do { printf("Please enter number :"); …
awfullyCold
  • 102
  • 1
  • 10
0
votes
1 answer

C++ while (true) vs while (!something)

So let's say we have a bit of code in which we want the user to say something specific, but we want to give them infinite tries if they get it wrong. I would use a do while loop. #include #include int main() { std::string…
Domani Tomlindo
  • 239
  • 1
  • 5
  • 12
0
votes
1 answer

syntax error on main{} bracket, "expected while"?

I am completely stumped. No matter what I do it my compiler thinks I need a while loop at my last printf? It just keeps asking for things that don't make sense. When I add them in it just tells me that it shouldn't be there, and when I remove it i'm…
0
votes
1 answer

php display categories and subcategories

Ok now i have two table categories and subcategories like this Categories: id title description Sub Categories: id catid title description Now the 'catid' of the subcategories will have the value of categories 'id' and i want to…
Keshav Nair
  • 423
  • 1
  • 14
  • 24
0
votes
0 answers

Looping back to my if statement after using a switch statement in conjunction with a do/while statement

Hello there fellow coders. Just a noob here that is currently stuck in a pickle. I am coding a math training program, and am needing to loop back to my main menu. There is an infinite loop i am having trouble getting out of. If the user keeps…
0
votes
1 answer

how to get an if statement to restart from a certain line of code in java?

I am a student who is relearning java and I am looking for a way to have player 2 rolls again (since if a player rolls a double they get to roll again), however, if I use continue then it will jump back to the top of the do while statement. Any…
0
votes
1 answer

Forcing user to enter an Integer using a While loop in C

I am trying to get the user to enter a integer to be later used in the program I want it to force user to enter an input until it is an integer. When I run this code it goes on an infinite loop like so: Enter smallest operator: Enter smallest…
Uluc Ozdenvar
  • 59
  • 1
  • 7
0
votes
5 answers

Function that prompts user for integer value and checks for valid input

I currently am stuck on a small part of an assignment I need to do. One requirement of the assignment is "Call a function that prompts the user for each of the values of the coefficients a, b, and c for the quadratic equation and returns the…
rmgk
  • 41
  • 5
0
votes
1 answer

While Loop having issues

I'm trying to create a function to bucket data into deciles using a different field as the weight so I can have equal exposure buckets. In doing so I've created a simple example that I'm trying to get into 3 buckets. I'm really stumbling on the…
0
votes
3 answers

Problem with a do-while loop and creating an alert

I'm new to javascript and I'm trying to make a program to continuosly click one button unless another button is present. (I'd also love to get an alert when the second button appears but I don't know how to do that.) This is what I got: Do {Let…
S. Grun
  • 5
  • 3
0
votes
1 answer

Loop runs ad infinitum, regardless of int entered

I've take a break since I posted this and have read through half of the C programming book I'm studying (Harvard cs50 book). I should be able to solve this by now, yet am unable. The program runs in a continuous loop, no matter what integer is…
0
votes
4 answers

Why is my do-while loop breaking too early in java?

So my issue is while this runs, as soon as you input one it will only print the next switch and ends program without allowing input of the next choices. Here is what I have done so far. I had taken the while(choice == 1) and put that in the case…
0
votes
1 answer

Do/while loop in node.js to get total tweet counts only runs once

When making a get request to twitter api, it returns all the tweets in the array tweets.statuses. We can find the total tweet counts using tweets.statuses.length. In one request it can only return a maximum of 100 tweets even if there are 1000s of…
Asad Feroz Ali
  • 362
  • 5
  • 15
0
votes
1 answer

Do-While Loop Error - Not Repeating Play Again Game

I am facing with an issue where if a user want to play the game again, it will not prompt the user to key in the numbers, instead, it would print out statements and I am wondering why is doing that... It works perfectly fine if a user types in "No"…