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
1 answer

While loop to find space character - Java

So new Java developer here, been at it for a week and decide to get my hands dirty. I have been trying to create an application wherein a user can register for an account. I am at the part where the user has to enter their full name, and the program…
AmsKumar
  • 93
  • 1
  • 10
0
votes
1 answer

Test if number exist in database, create new one if it exists

I have a hurtle I just can't figure out. I want my code to: Create a random number Test if it exist in the database If it exist, create a new random number og do number 2. again. If it don't exist, create it in the database. I've tried the…
Rasmus Kjeldsen
  • 161
  • 2
  • 13
0
votes
2 answers

Getting the Timing of a Specific Part of Code in a Loop in C

Description of Problem Below I have a program that is performing two simple addition and multiplication operations. I am then storing the sum of these two simple operations in two respective variables called total1 and total2. In terms of…
Anthony
  • 83
  • 1
  • 7
0
votes
2 answers

VBA - Find how many times a cell is present in a column and then print the cell and its count

The idea hear is that a column contains 80,000 rows filled with values, and I want to create a VBA macro which will read every value and count how many times is present in the column and print it, but the problem is that when the loop reaches the…
Tony
  • 5
  • 3
0
votes
2 answers

printing a print statement after a certain amount of tries in a loop

I am new to coding. I created a guessing game, and it works well but, I would like to know how to make it so that after the user attempts guessing the number 3 times, they get a hint which I put on the last line, but it is currently unreachable, and…
0
votes
0 answers

JAVA Basic Shopping Cart Program

I'm trying to create a simple shopping cart application. The problem is with the totalPrice that is displayed in the end (startScanning() method). I'm trying to to make the user input one of the four items as many times as they want(thus the…
0
votes
0 answers

vb.net application not responding during loop

I've been trying to create a program which displays every possible combination of letters, alongside some punctuation. It starts by running a single character through every letter, then it adds another character, and does the same thing, with each…
0
votes
1 answer

Java Loop Logic with StringBuilder (Hangman)

So my issue is that I have most of my code set up, except the loops I have tried always seem to iterate extra times, throwing off the correct/incorrect count. I have been stuck trying different combinations of while and for loops and this was the…
anon
  • 11
  • 2
0
votes
2 answers

C++: Program "Not Responding" When Executed

I was working on this C++ homework assignment, and when I tried to execute, the .exe file kept "Not Responding." I closed the program and Codeblocks. When I tried to open another program I know works to re-start my assignment and try again,…
amykp
  • 45
  • 12
0
votes
4 answers

Getting new colors randomly with loop

I am trying to randomize colors by generating random number, then applying it to array to get an color array containing font-color and background-color. At every "skill" I want to have unique color scheme. So each time I loop skill array I loop…
Jaakko Uusitalo
  • 655
  • 1
  • 8
  • 21
0
votes
2 answers

error in do while loop

public Login ClickGetStatus() { //IWebElement btnGetStatus = driver.FindElement(By.XPath("//*[contains(@id,'GetStatus')]")); do { buttonName_GetStatus[0] = "abc"; Thread.Sleep(3000); bool is_displayed = …
Hargovind
  • 73
  • 11
0
votes
1 answer

Triple Conditioned Do-While Loop With Multiple Logical Operators

I'm unable to get the do-while loop below work in Java. Thanks for your help. do{ //User enters a value for x //User enters a value for y }while(x==-1 && y==-1 || x==5 || y==10); What I'm trying to do is simply: a) If x and y BOTH are -1 then…
0
votes
1 answer

Passing and changing an object's parameters into a do while loop

What I'm trying to do is simply have the battle end when either the player or monster's HP has reached 0. As it stands the loop continue to run even after the numbers run into the negatives. I can't figure out if it's the loop itself or some issue…
Red Rabbit
  • 115
  • 1
  • 11
0
votes
1 answer

Replacing do-while loops as convergence query in Fortran OpenMP

I have build a program that uses Differential Evolution to optimize atom positions in regard to their pair-wise potential and now want to parallelize it with OpenMP to which I am quite new. The Differential Evolution uses an overall do-while loop in…
Rainer Hohn
  • 53
  • 1
  • 6
0
votes
0 answers

c++ Do-while loop inside switch-case Statement

Could someone explain me the program flow for this step by step? I don't understand how the program enters the do-while loop in the first place as n%3=1 and Case 0 should not be entered according to my understanding. Thanks in Advance! #include…