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.
2,696
questions
2
votes
4
answers
54
views
Do-while or while loop that will keep taking an input from user but will terminate after I input the string "exit" (case insensitive) in c language
#include <stdio.h>
#include <ctype.h>
int main() {
char str[100];
char out[] = "exit";
do {
printf("Enter a string: ");
scanf("%s&...
0
votes
0
answers
11
views
Why does my do-while loop goes into an infinity cycle? When I use it it works perfectly, but when I upload it where i have to it goes to infinit loop
int main()
{
const char* kezdo = "Kerlek valassz egy funkciot: (1)Adat hozzaadasa, (2)Adat torlese, (3)Adatok kiiratasa, (9)Kilepes: ";
int valasztas = 0;
bool getout = false;
do{
...
0
votes
1
answer
27
views
I have a problem with do while loop in my project
This is the program, I designed it to be a phone store, and the problem I am facing is that after you choose to go back, the program will go back normally, but after you choose to buy the next time it ...
0
votes
1
answer
15
views
Is Camel doWhile a real do-while?
I read in the Camel documentation that we can use looping with a doWhile construct.
But it is not clear to me: does the Camel's doWhile behaves like a classic do-while (executing at least once without ...
0
votes
0
answers
16
views
Loop over next_url in API call
I'm using Node on AWS Lambda to call an API which gives X results, if more exist, it provides a "next_url" URI to call for the next set of results.
How do I continuously loop, passing the ...
0
votes
1
answer
21
views
Looping through REST API calls improperly breaks at first iteration or last iteration
I am trying to send a REST API call to retrieve a lot of data. Now this data is returned in JSON format and is limited to 2000 records each call. However, if there are more than 2000 records then ...
0
votes
1
answer
35
views
read-while loop with variables in bash -- equivalent in Python?
Currently refactoring some old code and looking to convert some bash scripts to python.
We have a small piece of functionality written in bash that's similar to:
var1=$1
var2=$2
var3=$3
while ...
0
votes
0
answers
27
views
Java - How to handle Exception Handling in a Looping Switch Statement [duplicate]
I'm just trying to figure out how to implement Exception Handling in a Switch Statement which will then loop me back to the menu for input again. What I am trying to catch is String input where it ...
-1
votes
1
answer
45
views
C++: For two different functions with do-while loops, why does x+=y give the same result as x=x+y in one function but not the other?
For function A below, I get a different result when I use est += XXX as compared to using est = est + XXX. The former gives a result of 1.33227e-15 while the latter gives a result of 8.88178e-16.
On ...
-1
votes
2
answers
51
views
Do while loop keeps looping c++
So, I want this program to keep prompting when the number of digits isn't 16, that part worked, but whenever I try to input 16 digits it loops without letting me type anything in again. This is what I ...
0
votes
0
answers
46
views
Cannot break do-while loop in Powershell
I have been working on this PowerShell script. I'm still pretty new at this. The way it works is that I give it a list of servers which it goes though and restarts the App Pools 1 by 1. I have been ...
-1
votes
0
answers
11
views
How can i loop this after the user input a value that is not a,b,c?
What should I use? do-while? for-loop? if statements?
how can I repeat the question "Who is the Main Character of each movies or anime?" if the user input is not in the choices?
Scanner ...
1
vote
2
answers
43
views
adding elements to arrayList with do while loop
i can't add 2 values in this code , i tried with one variable but when i tried to fetch from user for the second time it didnt worked .so i put another one but still i can't add value from first ...
0
votes
1
answer
22
views
How can I work on aws regions in a while list in Bash
I am using this code to get my AWS region. I want working on them in a while loop.
awsRegionList=$(aws ec2 describe-regions | jq -r '.Regions[] | .RegionName')
while [I can't find the expression work ...
0
votes
1
answer
30
views
I just want my Goggle Sheets loop to stop when a specific cell = Total
function TRANSPOSE1() {
var spreadsheet = SpreadsheetApp.getActive();
do {
spreadsheet.getRange('F2').activate();
spreadsheet.getCurrentCell().setFormula('=IFERROR(TRANSPOSE(D18:D31),FALSE)...
1
vote
2
answers
66
views
"If statement" deleted, c code runs without problem, what is the reason?
When the if statement is deleted, the code runs without problems. What is the reason for that? This code gives the Greatest Common Divisor (GCD) of two numbers (m and n) the user should input.
#...
-2
votes
0
answers
21
views
Why do-while loop if we have while loop
Please someone clarify me if we have while loop why we use do-while loop in every programming languages like why it needed because we can done same thing with while loop
0
votes
0
answers
5
views
DoWhile seems to require repetitive input.nextLine()? [duplicate]
thank you for taking a look at my question.
This is a Java file when executed, takes in a name of a student and corresponding grades and when you type nothing in for the name, it computes the average ...
-1
votes
1
answer
64
views
Java loop gets stuck and doesnt exit
So im creating a game of blackjack as part of an assignment for my college. I have to create some kind of method to allow the player to Hit or Fold.I decided to write this part of code which checks ...
0
votes
3
answers
47
views
Why does my code run a while statement when the while statment is finished?
I'm trying to make a rock, paper, scissors game, but each time I run it, when the game is supposed to be over, it asks the user to input rock, paper or scissors again. It doesn't add the result of ...
0
votes
2
answers
39
views
Return to menu after the input result
I'm working on a Show-Menu PS script. After the user gives in his input and he gets the result. He should see again the Menu and not "Enter the user ID: "
I know this is possible by removing ...
-2
votes
1
answer
32
views
Why does a while loop and a for loop only return me the information of the last iteration?
Here I am playing around with the coin gecko api. I am trying to log the price of bitcoin while 10 is not equal to 0, so basically 10 times. It works fine, only the iteration doesn't show accordingly. ...
0
votes
1
answer
22
views
Do-While Loop When Media Player Is Playing
In my app there is a "Start" button.
The desire result is whenever the media player is playing,the text of the button should be change to "Stop", and when the music stops the ...
0
votes
0
answers
14
views
Java Exception throw creates an infinite loop
I have established a do-while loop to verify user input is valid. If a 0 or negative number is entered, the Exception is thrown and the catch prints out. However, if a string is entered (i.e., ...
0
votes
0
answers
36
views
Validating user input in a switch statement inside a do/while loop in java
I am a group member in a project for a programming class. The assignment is to create a single user program that can allow for all general functions of a library. I am attempting three things at the ...
0
votes
0
answers
35
views
How to check if input is not integer [duplicate]
So this is an infitine loop until number 6 is entered, if a number that is not a choice is entered it pritns the error and start the loop again. But, when the input is not an int it prints the menu ...
0
votes
2
answers
29
views
Follow DRY principle
I have an implementation of following kind-
int max_count = 10;
main() {
Writer writer = //initialise writer;
List records = new ArrayList();
while(true) {
// some functionality
// ...
0
votes
1
answer
33
views
scanf inside an If statement on a do while loop messes up the inputs
When the input is a negative integer, the program should ask if you want to reset.
It worked fine when I test it with a negative integer. But when I try a positive integer, it doesn't work (I have to ...
0
votes
1
answer
50
views
do/while loop with cin.getline parsing to string doesn't compare values to break it
So I have this type of "menu" in a do/while loop
do {
cout << "Press 0 to export IDs, exit to exit, or any key to continue to menu:\n";
cin.getline(choice,...
-1
votes
1
answer
58
views
Why do I have a line break?
there is a problem with the code. Displays an error "std::out_of_range at memory location". during debugging.
The task of the code is to find all the letters "A" in the text and ...
0
votes
0
answers
20
views
Program Exiting Loop for No Apparent Reason [duplicate]
I am trying to make build a little program that would loop as long as the user presses a specific key but for a reason I can't see, it exits the loop
Here's what it looks like
int main()
{
char ...
0
votes
1
answer
36
views
Can someone explain the error in my C# do while loop? [closed]
Simple question I suspect but I can't find an answer online. I'm trying to get this do while loop to loop infinitely until the number seven is given.
namespace Practice_code
{
class ...
-2
votes
1
answer
58
views
How to print number 1 to 10(in that sequence only)using loops(java) if int i = 10
Output must be
1
2
3
4
5
6
7
8
9
10
I have tried
While loop but it prints from 10 to 1
0
votes
1
answer
59
views
How do I loop adding the month to each date until the condition is met? google apps script
How do I loop adding the month to each date until the condition is met?
Explanation : I want to add 3 months to each date every time until the annual column (column D) will be greater than the today's ...
0
votes
1
answer
43
views
Getting repeated user input using while loops and if statements
I am wanting to create a simple programme that will terminate when either the number 2 or 3 is guessed and whenever a number is not in that range I want an error message to pop up and say try again ...
-1
votes
2
answers
43
views
JS - After Do-While loop, the rest of the function doesnt execute
loadNewPages = async () => { //TODO this needs to be looping
this.setState({ pageCount: 3 })
let response;
do { response = await getMembers(this.state.pageCount++, this.state....
0
votes
1
answer
51
views
how to use a do-while loop in a class?
how would I create a do-while loop to verify that the user input contains no special characters. If it does contain special characters, how would I make it restart the loop? In my loop, it still ...
0
votes
1
answer
45
views
Receive average scores and check the number of scores in a range | Java
Write a java program that reads the grades of 10 students, which is from 1 to 100, from the entrance, specifying that the scores of some people are from 90 to 100, some people are from 60 to 89 and ...
0
votes
1
answer
37
views
How do I add a do-while loop in this program so that if the input is less than 4 it doesn't print anything
#include <stdio.h>
int main () {
int row, i, j;
printf("Enter a number: ");
scanf("%d", &row);
for (i=1; i<=row; i++) {
for (j=1; j<...
0
votes
0
answers
24
views
User input to determine if main function restarts or ends
I'm working on a small project right now that allows a user to choose an array editing function from a switch statement. Unfortunately, I coded it poorly (I can't make the switch menu its own function ...
-1
votes
1
answer
32
views
unable to give input everytime for char using do while loop
I am not able to give input every time. It is skipping in between and I can only give input at alternate times I have created a do while loop and trying to take input as char.
#include <stdio.h>
...
-1
votes
2
answers
49
views
do-while in fibonacci sequence repeating answer
I made a program about Fibonacci program. I would like to repeat the program so I used do-while loop. However, it seems like the last two numbers from the previous result keep coming. It is supposed ...
-1
votes
2
answers
50
views
I am trying to get a JavaScript Program to Print a letter grade and Percentage based on a average using a switch statement but the answer comes up NaN
In my program I am using a do-while loop to prompt for grades until a -1 is entered and then increments the amount of grades inputted. A while loop then checks if the grade isNaN or less then 0 or ...
0
votes
2
answers
39
views
Java can't find symbol defined in a try-catch block in a do while loop [duplicate]
I keep running into this error when compiling this code here:
TryTryAgain.java:52: error: cannot find symbol
if (file.hasNextInt()) {
^
symbol: variable file
location: class TryTryAgain
It's not ...
-3
votes
2
answers
83
views
Java Using do-while loop
Using do-while loop, Write a program that will ask for five (5) integer numbers. Determine the highest and lowest value.
Consider the sample output.
Output:
Enter 1st number: 5
Enter 2nd number: 10
...
1
vote
3
answers
85
views
display a sorted linked list with every new element in c
So I am trying to make a program in c that will let the user enter numbers until the number 0 in entered. Then create a linked list that will sort the entered integers from smallest to largest. Here ...
0
votes
0
answers
25
views
C++ Homework works on Visual Studio Code but not Code Grade Auto Test [duplicate]
I have this assignment for my coding class which I've completed on vscode. However, when I run it on CodeGrade the autotest gets a different output. The loop continues forever, but when I run it on ...
0
votes
0
answers
35
views
Do while loop not working inside a function in C [duplicate]
I would like the below code to repeat the question "How many cents are you owed?" if the user inputs a negative answer. I've implemented a do while loop inside a function, which doesn't seem ...
0
votes
1
answer
28
views
Fail to ask the user to repeat or exit the program using Do ... While loop in C [duplicate]
I try to make a program that the output will be the classification based on the input grade (by character). Here is my code:
main ()
{
char choice,grade;
printf("Enter a grade: \n");
...