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# Blocking specific types of answers using a sentinel value

I am writing a code to get the highest mark and lowest mark. It also collects the average. It uses 999 to exit out of the do loop. I need to get it to stop adding the invalid answers as well as the 999, but I can't get it to work. (mark != 999)…
0
votes
3 answers

How do I validate values in the correct range in loops?

I have a question: how do I validate that the value entered in the correct range and ask the user to reenter the choice? I already have the code listed below but it keeps looping instead. For example, if player 1 enters 6, it should say incorrect,…
0
votes
5 answers

combining two do while loops into one or any better refactoring possible

I have an HTML video player that runs random videos. I have the following function that tests if the video is marked completed based on the video seen percentage. VideoCompletionPercentage is a global variable that is set by reading it from the…
melleck
  • 306
  • 4
  • 15
0
votes
2 answers

Do while loop that calculates average while not accounting for negative numbers?

Need to write a javascript code that will prompt a user to enter numbers until a negative number is entered. Then calculate the average of the positive numbers only. Any help is much appreciated. Here is what I have so far: do{ if(num < 0){ …
0
votes
1 answer

Do While Loop Not Looping through Folder

I have around a 1000 files in a folder that I want to loop through individually, process the data, then copy/paste in a separate *.xlsx workbook. There seems to be an issue with the code that is "processing" the data because when I try to come back…
0
votes
3 answers

C++ total keeps going up

Hello this is my first program with a do-while loop and its taken me a little while to get it down. I need to have the user enter 2 numbers, and raise the first number to the second number. I have finally got the coding to ask if "they would like to…
0
votes
1 answer

JAVA - How can I make sure program only continues with a scanned int?

I'm learning to program in Java and I'm working on a pizza-ordering console program. I've gotten the entire program to work, but I want to fool-proof it. Three places I ask for an int input, but when I type a char or a string, the program crashes.…
0
votes
1 answer

Prompt the user to ask the input until the condition is met?

int32_t number; uint32_t x = 1; puts("What number do you want to count: ?"); { scanf("%i", &number); printf("You typed%i.\n", number); while(x < number) { printf("%i and then \n", x); x++; } if (x > 100 || x <…
Chaite
  • 23
  • 7
0
votes
1 answer

Do-Until loop ask twice value

The problem is with loop DoUntil. The script must take the URL, than ask what to do with him and gave the result after the user pick the number(1-4) and with output give the menu again, and user can pick another number if he want or finish the…
user6236445
0
votes
3 answers

Looping within switch statements

I am wondering what the most efficient method for looping within a switch statement would be. Below I have a userInput variable and would like suggestions if an if/then statement would be better implemented here to continue my menu selection until…
0
votes
2 answers

How to resolve Exception in thread error (ArrayIndexOutOfBoundsException) in Java?

This code is to input n integer values and calculate the no. of even and odd values among those inputted values. This java code shows ArrayIndexOutOfBoundsException when used do..while loop, however when used for loop it worked fine. Haven't changed…
meisner97
  • 9
  • 6
0
votes
1 answer

Do-while loop not ending

This is a portion of my code for a Battleship game. The looping doesn't stop when I sink all of my ships. I take the input for the shoot array from player and the compshoot array from the random function. do { System.out.println(); …
0
votes
0 answers

How can i make logic program for datatype string in Java?

I have a problem making a program that uses the type String. I want my program to make a loop if the user don't enter his first name. public class formregister { public static void main(String[] args) { String nama_depan =…
Moel_Chan
  • 1
  • 1
0
votes
3 answers

C: Do-While Loop Repeating Too Much!

I have a small program that which is confusing me. I am trying using a loop to take input from user. In case input is wrong, it is repeated again but if it is right, it exits. The code snippet is: void main() { char user_status; // Checks User…
Ishan Sharma
  • 700
  • 2
  • 10
  • 19
0
votes
1 answer

How can I create a proper do-while loop using Powershell

I want the script to generate a random last group (Key0) and try to unlock the drive on each iteration with the concatenated string (Key), but is not working. I execute the script and it just makes one try. It seems the while is not working. Do { …