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
3 answers

Java - How to end a process of a while function

I need a program that asks the user to introduce up to 10 names (to end, the user could type "fim" [that is end in Portuguese]). My current problem is how to terminate the program if the user reach 10 names. Here is my main function: public static…
user9119361
0
votes
2 answers

Returning a value with pointer ( C program)

I'm a beginner in C and below is a program to find the position of a given digit. My first function works but i can't say the same for the 2nd one(digitPos2) that returns the value from a pointer. I'm not sure what is wrong and why. #include…
0
votes
4 answers

looping back to start of do while loop [C++]

I need help for looping back on the start of the program [C++]. #include #include using namespace std; int main(int argc, char *argv[]) { srand(time(NULL)); int rand_number = rand() % 101; int number; int counter…
user8916243
0
votes
5 answers

Do not understand this Infinite While loop

Can someone please explain to me in layman's terms what's going on with this snippet of code? I understand it's a function used to get the first character then discard the remaining input but I am confused with the last while loop. When I googled it…
MAD
  • 31
  • 4
0
votes
1 answer

PHP - repeat retrieve XML if value is not correct

I have a code in PHP to works with XML: $data_measuranment = file_get_contents($value, false, $context); $xml=simplexml_load_string($data_measuranment); $json = json_encode($xml); $array[] = json_decode($json,TRUE); The values of my…
Alex
  • 15
  • 4
0
votes
0 answers

Not getting decreasing gas in a C++ program

Ok, so I have this program that is suppose to simulate an "Uber" driver picking up and dropping off customers and informing him of how far he has driven and how much gas he should have felt. I basically have it all worked out but for the life of me…
csiket715
  • 51
  • 7
0
votes
4 answers

do/while and if/else problems

I have to put in an extra "test score" to get an answer. (i.e i have to enter six 5' to get 25) I can't get the do/while & if statements to loop if there is more than one number outside the "while" range. I haven't been coding for very long, a…
0
votes
1 answer

MySQL Stored Routine Error

I'm creating Stored Routine in MySQL right now, and I got this error while querying. SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your SQL server version for the right syntax to use near…
Mohammad Iqbal
  • 29
  • 1
  • 10
0
votes
1 answer

Using a do-while to search for an element in a structure

I have a struct for employees, id, age and salary. I need the user to select what employee they would like to edit by typing their user ID. I need to use a do-while to search through the struct until the user enters a valid user ID. So far I've got:…
0
votes
1 answer

Reusing previous string in Do loop

The idea is to reuse the string that was used in the previous iteration of the loop. public void StringMain() { string temp; int times = 0; do { string input; string reuse; if (times == 0) { …
James9oo0
  • 159
  • 12
0
votes
1 answer

Bash: Can I loop commands outside of the If Branch as well?

I am working on a bash script and I'm having some trouble with the while-loop. Below is the section of code that I need help with. #!/bin/bash set -e # *start* read -rp "  written by: " bit tput sgr 0 cat /home/sir/rmf/posted |…
345422
  • 103
  • 5
0
votes
1 answer

Dice Toss Game on java

I'm coding a dice roll game on java with some set rules. The player seeks to obtain a 7 or 11 in the combination of dice to win. If on the other hand he gets a 2, 3 or 12 loses. If during the first throw you do not get a 7 or 11 (with which you…
Anguis Nox
  • 21
  • 9
0
votes
1 answer

C# replace do..while with for loop

I usually know how to replace a do..while loop with a for loop, but in this case variable check2 is used 2 times for different loops with got me confused on how to correctly replace it with for loop. public static void RelayChat(ref int con, ref…
0
votes
1 answer

VBA to loop through text delimited files in a folder and export as csv

Need assistance with figuring out why my code is not looping through my folder. It loops the same text file over and over again. When I put a break in and run the code, it appears that the next file in line is correct, but it opens the prior…
Starks
  • 1
  • 1
0
votes
2 answers

Java: Infinite looping within while loop when trying to limit user input with do-while

static int prompt(set x) { Scanner input = new Scanner(System.in); do { System.out.println("Please enter an integer within the specified range."); while (!input.hasNextInt()) { System.out.println("Please enter a…
1 2 3
99
100