FAQ Database Discussion Community


How to initialize a variable in a do while loop without passing the value until the loop has closed?

java,scope,do-while
I've been writing a program that requires the input of a number between 1 and 4. In order to prevent input of numbers outside the range. However the variable keeps passing to another piece of code and causing the program to fail. This is the do while loop: do {...

How to run a certain method every time a button is clicked with changing buttons in javascript?

javascript,jquery,button,do-while
I want to be able to run the content() method every time a button is clicked with the id of the button as the parameter. This method removes the old buttons and displays new buttons. This is the code I have so far: do { selection = $('button').click(function() {return this.id;});...

Character table-based searcher doesn't work

c,string,loops,do-while
The following code is supposed to return the character that is registered in the table set and has been determined in the source string. int find (char source[], char set[]) { int i, l = strlen(set); int exit = 0; for(i = 0; source[i] != '\0';) { do { if(source[i]...

loops when user input is wrong and increments when input is right

java,do-while
Part of my homework is to create a program that asks the user to input item's price that ranges from 1-1000. If the user enters a price not in the range then the program loops back to ask the price for that same item no.(item no. ranges from 1-10). If...

Unwanted double repetition in C

c,loops,do-while,repetition
Let's say I am writing this piece of code: char c; // c from choise. do{ printf("Please choose one of the following operators:\n"); printf("+ for Addition\n- for Subtraction\n* for Multiplication\n/ for Division\n"); printf("= for Assignment and\nE to check if two variables have the same type and value.\n"); scanf("%c", &c); }while(c!='+'...

Do-While loop in C - error at printing

c,printf,do-while
I am making a little program that takes as input the answer to the question "Are you an adult?" as a character like that: bool adult() { char answer; do { printf("Are you an adult? [y/n]\n"); answer = getchar(); } while (!(answer == 'y' || answer == 'n')); return (answer...

Ruby code efficiency

ruby,while-loop,do-while
Is there a way to make this code shorter and simpler? loop do if possibleSet.split(" ").map(&:to_i).any? {|e| (e<0 || e>12)} print "Please enter valid numbers (between 1 and 12): " possibleSet = gets errorinput = false else errorinput = true end break if errorinput end ...

How do I clear an array at the end of a do-while loop in C++?

c++,arrays,recursion,do-while
The purpose of my function is to generate 8 random letters n times (specified when it is compiled). I approached this by writing two functions called genNumbers - which generates 8 random numbers (between 0 and 25) and places them into an array called numbers, and convert - which converts...

c++ Do-While, Random Words From Array For String With No Repitition

c++,random,do-while
What I want done is to have an array of words then a string is assigned a random word from the array but no string can have the same word. I tried this but when it runs, it will only do the do-while once then go onto the next do-while...

c# - Print the prime numbers from 0 to 10,000

c#,for-loop,numbers,primes,do-while
Im currently trying to create a program that prints the prime numbers from 0 to 10,000 using only for,do while and ifs. I created this program but it doesn't runs static void Main(string[] args) { for (int x = 2; x < 10000; x++) { for (int y = 1;...

Do While and While Loops not working in C++ code

c++,while-loop,do-while
Hi I'm writing a C++ code that asks the user for an input as to which internet service provider package they are using, and then using that information the code calculates their monthly bill. However the following code is not working. { int choice; double hours; cout << "Which Subscription...

do while loop doesn't get out of the loop?

java,do-while
I'm pretty sure this should work... But even if I enter a 0 or a 1 it still asks me to pick a colour. Am I being stupid or should it be exiting the loop if I enter a 0 or a 1? public static int setColour() { EasyReader keyboard...

Get variable outside WHILE in SHELL BASH script

mysql,bash,shell,sh,do-while
How echo variable x and y outside "while" in SHELL script: #!/bin/bash x=1 y=1 mysql -e "show tables like 'do97_%';" --host=localhost --skip-column-names -u login999il --password=e9999999999df54y basenamel | while read tables; do mysql -e "SELECT id, tolbox, del_time FROM $tables WHERE deleted=0 ORDER BY create_time DESC LIMIT 0" --host=localhost --skip-column-names -u...

Loops repeats twice

php,loops,do-while
$n = 0; do { echo "START PAGE\n"; echo "total pages: " . $response->PaginationResult->TotalNumberOfPages . "\n"; echo "current page: " . $currentPage . "\n"; echo "iteration: " . $n; if ($n == 2) { break; } $j = 0; foreach($response->SaleRecord as $SaleRecord) { if ($j == 2) { break; }...

Redirection based on variables assigned within while loop setup

shell,while-loop,do-while
I want to access while loop variable out side the loop while read line do ... ... ... done < $file > /home/Logs/Sample_$line_$(date +"%Y%m%d_%H%M%S").log In the above example whatever the log file is getting generated that doesn't have the value for the line variable. i.e. $line is not working here....

java do while loop keeps repeating and I can't figure out why

java,do-while
So I've attached a debugger, and tried different inputs and I can't seem to figure out why this won't get past the loop. When ran I enter "l" or "L", then entry gets set to that, then input is set to the capitalized version and then it repeats. public static...

SAS - Do a loop while a column value doesn't change

loops,sas,do-while
I'm trying via SAS guide to use a loop (via PROC LOOP) to create a new column with a increment ID whenever the value of a specific column changes. Just for example I'm looking for something like this: Date | Name | Status | ID ------------------------------------------ 20150101 | Tiago |...

Why does program crash after exiting do-while loop asking for input in C?

c,string,input,do-while,string-length
I am having trouble with correctly using a do-while loop to keep asking for another string if the one input is longer than what you want. After entering a string which is too big the program expects another but after I input an acceptable one the programs crashes instead of...

C++ do…whille loop duplicate prints with getchar function

c++,loops,duplicates,do-while,getchar
The code below is printing "Menu" twice when input is different from 3. do{ puts("Menu"); option = getchar(); } while (option != '3'); ...

My do/while loop messes my program up the second time around

java,java.util.scanner,do-while,palindrome
The issue I am having is once I input a word like "non" I get back it IS a palindrome. I then type "Yes" as I ask "Keep Going?". It starts back up at "Type Word:" and I type "non" again. This time however I get back it is NOT...

Visual basic 2008 - Do…While until infinite loop when shuffling 52 card deck

vb.net,visual-studio-2008,boolean,infinite-loop,do-while
I'm starting to make a Hearts game in VB2008. Currently I'm stuck with the dealing: For q = 0 To 51 Do Randomize() dealrand = Int(Rnd() * 51) cards(q).Image = pics(dealrand) Loop Until dealused(dealrand) = False dealused(dealrand) = True Next What I'm trying to do is check if the card...

simple do/while loop infinite loop issue

javascript,loops,do-while
Okay first off, im very new to javascript and doing some tutorials to try and learn the language. My problem is probably something incredibly simple, but i can't figure it out! Okay so ive made a very simple do/while loop. All this should do is print "do condition, only once"...

Matlab: Looping through an array

matlab,loops,for-loop,while-loop,do-while
This is my one dimensional array A. containing 10 numbers A = [-8.92100000000000 10.6100000000000 1.33300000000000 ... -2.57400000000000 -4.52700000000000 9.63300000000000 ... 4.26200000000000 16.9580000000000 8.16900000000000 4.75100000000000]; I want the loop to go through like this; (calculating mean interval wise) - Interval length of 2,4,8 (a(1)+a(2))/2 - value stored in one block of...

GPA Calculator in C

loops,for-loop,do-while
I'm trying to get this code to calculate a class's average GPA. The problem I'm having is that I seem to have made a mistake in my do...while code, because, when I run it, it constantly loops back to asking me to input another GPA, rather than asking if I...

Trying to calculate the average of inputs given using do-while and while loop but it keeps stopping

java,while-loop,average,do-while
The main gist of the script is to keep asking for grades until the user inputs a negative number. Once a negative number has been input, it calculates the average of those grades. The grade that was input by the user can only be 4-10. I've been for hours now...

how to find out number of levels of categories in wordpress

wordpress,for-loop,while-loop,do-while,wordpress-loop
I'm wondering about how WordPress stores total number of levels of categories ? and how do they make a loop to print them ? could you please anyone explain this?

Simple Javascript prompt validation loop not working

javascript,html,while-loop,do-while
I cant seems to get this to work. <script language="JavaScript"> var name = null; do { var name = prompt("Please enter your full name",""); } while(name != null); </script> ...

My do while loop is running once more than it should (I think)

c#,database,loops,do-while
this is a database program and by entering a number 0-7 you can do different things with the data files. Whenever I try to quit by entering a 0 it sends me through the loop again and then once I put in another 0 it will quit. static void Main(string[]...

How do i fix this simple program? guessing game

java,loops,if-statement,joptionpane,do-while
Hello please please please can someone help me. I am writing a program where the user can enter a maximum number for a guessing game and using a random generator he/she would have to guess the number from 1-to the max number. i have done most of it but i...

Trying to get program to repeat

java,loops,do-while
The program checks to see if the email address entered contains a @ and a .edu if it doesn't it needs to go back through the steps, I think I can use a do-while,but I haven't got one to work yet, how would I nest my if-else statements in a...

Long Running VBScript File Alert

loops,time,vbscript,do-while
I am trying to construct a VBScript file to remind teachers (once they have logged in) in the school I am in to take the register when it needs to be taken (in this case, 15 minutes into each lesson). I am doing this by an attempted infinite loop and...

fprintf(textFilepointer) print twice into file

c,file,printf,music,do-while
#include "aservelibs/aservelib.h" #include <stdio.h> #include <math.h> FILE *textFilePointer; int main() { int counter = 0; int note; printf("Press key on Axiom MIDI keyboard to display note number\n"); textFilePointer = fopen("/Users/jonnymaguire/Documents/Uni Work/Audio Programming /iap/iapProj/Builds/MacOSX/build/Debug/textp15.txt", "w"); do { if(textFilePointer == NULL) { printf("!Error Opening File!"); } else { /*get frequency from user*/...

Foreach loop (or do while maybe?) - Want to return only one record depending on page

php,loops,variables,foreach,do-while
Solved this with edited code below. Thanks to all who helped! I have two records in my db. Each record has 6 fields (challengeId, partnerName, code, challengeTitle, description, image_url). I select a given partnerName from my parent page view to go to my child page view. I was using a...

Any suggestions or improvements?

c,loops,for-loop,do-while
Can I use the for loop to replace the do...while loop in this program? Any suggestion to make this program more simple? This program ask the user to enter their option from 1 to 5 (if choice is another number the program will terminate) My code: int choice; char option;...

How to fix this basic program? Java do-while loop

java,loops,try-catch,joptionpane,do-while
I am writing this guessing game, which enables the user to enter a number as the maximum number. The random generator will then pick a number between 1 and the max number entered by the user. It will save and display the number of high guesses and low guesses. The...

Error when implementing a while loop

java,while-loop,do-while
I'm trying to write a method for requesting user input via dialog box multiple times which only stops requesting when an empty string is entered. Each entry needs to be added to a list, which I'll call aList. I'm using a bespoke import for the dialog box in my program...

while loop doesnt work fine, c++

c++,while-loop,do-while
I am actually trying to loop a menu. on the given character my program should respond according to my logic. on press '0' the program should exit, on '1' it should take some new values (which i am taking through a function) and on '2' it should print those values...

Do-While to ask user to repeat entire int main programme

c++,user-interface,main,repeat,do-while
Very new to programming and l can't find any basic explanation online or code that will work well for what l need. I have a fairly long piece of programme (approx 300 lines) it all works. This is the structure to give an idea: #include <iostream> #include <stdlib.h> #include <time.h>...

do-while loop in android app

android,eclipse,do-while
I'm about to program my first app. I would like to use a do-while loop. I want that a button calculates something out of edittexts. After That I want to ask the user if he or she wants to calculate something again. I think a do-while-loop would be great, also...

c++ Greatest Common Divisor

c++,algorithm,do-while,modulus
I am very new to C++ and am attempting create a function to implement the Euclidean algorithm that returns the greatest common divisor for two integer inputs. The current approach I am taking keeps crashing - can you help me understand why? int main() { int a = 0; int...

Select count breaks in do-while loop

php,pdo,do-while
Where I work we need to register computers into a database, before we just used pen an paper, but I was asked to create an easier method. So I made a small local homepage. The computers are registered by a tag and number. The tag combined with the number must...