FAQ Database Discussion Community


How to show mysql multi row / mysql_fetch_array results in a table?

php,mysql,arrays,table,while-loop
I am trying to show mysql_fetch_array() results in a table. I want to show guests name,their country and their agreed time who are traveling on a same date. Following code works fine. The code fetches the row values and prints it. $select_guests = mysql_query('SELECT name FROM van_sharing WHERE date =...

Simple Python Program - unsure with Range and loop

python,for-loop,while-loop,range
Here is the psuedo code I was supposed to create in python: PlayerOneScore ← 0 PlayerTwoScore ← 0 OUTPUT "How many games?" INPUT NoOfGamesInMatch FOR NoOfGamesPlayed ← 1 TO NoOfGamesInMatch Do OUTPUT "Did Player One win the game (enter Y or N)?" INPUT PlayerOneWinsGame IF PlayerOneWinsGame = 'Y' THEN PlayerOneScore...

c# error: is a 'field' but is used as a 'type' when trying to use while loop [closed]

c#,while-loop
I am going through the euler project with C# to learn the language and keep my coding skills sharp over the summer break (I'm a college student). So I am very new to the language. I tried to look for answers to this error but all the other similar questions...

Loop PHP check until text within webpage has been found

php,file,loops,while-loop,find
On pressing the submit button, I want the PHP code to check to see if a string exists within a webpage on another website. $random = rand(100,1000); strpos(file_get_contents('website.com/url.php?username='.$username), $random); So, until the code has managed to find the value of $random, it won't continue with the rest of the script....

What is the error in this python program?

python,python-2.7,while-loop
I am just recently learning to code in python. I am trying to write a program, where given integer will give an output with a root and power (range is set 5 for instance). Here is the code: user_input = int (raw_input ('Enter your number: ')) root = 1 pwr...

Converting fopen to curl using while loop

php,curl,while-loop
Hi all I created a function (PHP) that basically opens a text file with a list of dates each date on it's own line. I then use a while look to go through each line of the file to see if a date listed matches todays or if theres no...

Java Scanner not reading newLine after wrong input in datatype verification while loop

java,while-loop,java.util.scanner
I've looked at similar questions and tried to follow the answers that solved the issues that others have had but putting the sc.next() or sc.nextLine() after the while loop causes it to go into an infinite loop. The problem is if a user enters incorrect input (nothing or a number)...

While loop counter increasing “exponentially” in spite of using ++

javascript,while-loop,counter,nested-function
Background information I am setting up a function which creates a date array based on a start date and an end date. The function will receive start and end dates, which have first been formatted to year-month-dayT12:00:00:00 format and then converted into milliseconds with .getTime() format. My script I have...

while loop not looping / displaying count

java,while-loop
This method repeatedly reads commands and execute them until the game is over. The finished variable, when true, means that the player/user has hit Quit and wants to end the game - thus exiting the loop and executing till the end of the method. import org.apache.commons.lang3.time.StopWatch; private Parser parser; private...

Bash while loop stops unexpectedly

linux,bash,while-loop
I'm analyzing two scripts with some behaviour I don't understand: #/bin/bash tijd=${1-60} oud=`ls -l $MAIL` while : ; do nieuw=`ls -l $MAIL` echo $oud $nieuw sleep $tijd done | { read a b rest ; echo $a ; echo $b ; echo $rest ; } The while loop in this...

How to query multiple php values into a javascript variable

javascript,php,wordpress,google-maps,while-loop
I am using a php while statement to query latitude and longitude coordinates into a javascript variable. As of now it gets queried into separate js variables like var locations = [ [ "59.911968", "10.709821" ] ]; var locations = [ [ "57.701476", "11.97373" ] ]; But Im trying to...

Java 'do while' loop not working

java,loops,while-loop
I have this code: import java.util.*; public class Vormpjes { public static void main(String[] args){ String vorm; String nogmaals; double diameter; double basis; double hoogte; Scanner keyboard = new Scanner(System.in); do { System.out.println("Kies uit de 'cirkel', 'driehoek' of 'vierhoek':"); vorm = keyboard.nextLine(); if (vorm.equals("cirkel")){ System.out.println("Geef een diameter op (in cm)");...

How to save each line in a text file as new file

awk,while-loop
I have a tab delimited text file with 5 columns, and I'd like each row to be its own txt file that contains information from columns 2-5 and is named after column 1. For example, my txt file has hundreds of rows similar to this: sample1name_oligos primer forwardseq reverseseq sample1name...

Pygame nested while loop: [Errno 10054] An existing connection was forcibly closed by the remote host

python,while-loop,pygame
I am using pygame with pyscripter and pyopengl, and am trying to put a while loop inside the main while loop, but as soon as the game enters the inner loop, it repeats the loop forever and I can't get out running = True while running: keys=pygame.key.get_pressed() ## do game...

How to return a value inside of while loop

c#,while-loop,return-value
I have a method, return type is List<User>. In this method I have infinite while loop to accept information from another client over socket. Once a new client accepts, I will add this user into list and continue to listen for new client. I give the construction of the method....

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> ...

jQuery while loop stopping prematurely

jquery,while-loop,wordpress-plugin
I'm working on my first Wordpress plugin, a simple linked periodic table shortcode. In it I've set up a jQuery script that shrinks the font size within the table to fit within its parent. However, the loop stops short, leaving part of the table sitting in the parent's padding. Can...

unix awk column equal to a variable

bash,variables,unix,awk,while-loop
I want to print the lines that with two columns equal to a variable, for example, input: 2607s1 NC_000067.6 95.92 49 1 1 3 50 1e-14 84.2 2607s1 NC_000067.6 97.73 44 1 0 7 50 4e-14 84.2 2607s1 NC_000067.6 97.67 43 1 0 8 50 1e-13 75.0 and variables for...

Using a scanner loop across classes (Java)

java,debugging,while-loop,java.util.scanner
I am trying to use a scanner loop as a method in my input class, in my main method. I keep getting this error: Exception in thread "main" java.lang.NullPointerException at Blackjack.Input.getBet(Input.java:27) at Blackjack.BlackJackGame.main(BlackJackGame.java:23) Here is the loop (this loop is in a separate class) : public int getBet(int cash) {...

(JS) Why is my While Loop not working!? Perhaps I don't understand the basic concept

javascript,while-loop
Here's the code: var n = 4; while(n) { console.log("Hey!"); n = 5; } Am I right here: n is a variable, with value 4. while n = 4, print "Hey" in console. change value of n to 5. check if n = 4. n is not equal to 4,...

Why this for loop doesn't do the same that the while loop?

c++,for-loop,while-loop
I'm trying to implement the cocktail sort, and in the main loop I'm trying to use a for loop instead of a while, but it doesn't give me the same results. Here is the code of the while loop: template<typename T> void cocktail(std::vector<T>& vec) { std::size_t beg = 1; std::size_t...

Use “and” many times in loop in Python [closed]

python,while-loop
I tried to use and in a while loop but it seems to not work well. For example: while (A1==0) and (A2==0) and (A3==0) and (A4==0): With this one, it seems to end the loop for the first and second and, and not always all the conditions satisfied. Is this...

getchar() not working in c

c,while-loop,char,scanf,getchar
getchar() is not working in the below program, can anyone help me to solve this out. I tried scanf() function in place of getchar() then also it is not working. I am not able to figure out the root cause of the issue, can anyone please help me. #include<stdio.h> int...

Need help extracting variables from a While Loop in VB.Net

sql,vb.net,variables,while-loop
I'm a novice with my coding so forgive me if my question seems basic but I'm having some trouble extracting my variables from this While Loop in order to then use the results of my SQL query for validation. This script below is the event handling for a login button...

Buffered Reader read text until character

java,file,while-loop,bufferedreader,readline
I am using a buffered reader to read in a file filled with lines of information. Some of the longer lines of text extend to be more than one line so the buffered views them as a new line. Each line ends with ';' symbol. So I was wondering if...

How to combine multiple while True function processes?

python,function,python-2.7,while-loop,python-multiprocessing
I'm very new to programming and python, can you please help me with the code I wrote? I don't know how to get it to work. Must I use class for it? Also how can the same variable be used in multiple functions? Do I need the multiprocessing? Here's my...

Infinite while loop issues

c#,multithreading,while-loop
I just barely started programming in C# and I am running into a small issue with background threads running infinite while loops inside of them. A little background: I am trying to make a physical notification light for Outlook. Right now I am making it in a WPF Application to...

Plain JavaScript + bluebird promises asynchronous for/while loop WITHOUT USING NODE.JS

javascript,for-loop,while-loop,promise,bluebird
There seem to be many answers to questions on how to use bluebird promises to call asynchronous functions from a for / while loop, but as far as I can see, all require node.js to work (e.g. promise.method() or process.nextTick() ; e.g. such as: While loop using bluebird promises )....

Why am I getting a debug assertion failed error on running the code

c,loops,debugging,while-loop
When I enter a password in my program below and press enter I get a debug assertion error, specifically isctype.c line 56 Expression:(unsigned)(c+1) <= 256 Could someone help me get around this please? Code: int main() { int j=0; char pass[100]; int upper=0, lower=0, digit=0, sc=0; printf("Enter your password:\n"); scanf("%s",&pass);...

While Loop Problems: Math in SQL

sql,sql-server,tsql,while-loop
I wrote a procedure that adds all numbers from 1 to a given number (Input 3- you get 6, 4 you get 10, etc). I thought it was a fun little piece of code, so I thought I would turn it into a while loop (you start the loop, and...

Problems with while() loop [duplicate]

java,while-loop
This question already has an answer here: Comparing two integer arrays in java 9 answers The statement before the begining of while loop System.out.println("Value of i before loop = " + i); is not being printed and the value of i in the loop is not being printed starting...

python while loop non-exit

python,python-2.7,loops,while-loop
I'm writing a simple program and I just can't get out of this loop. What i want to do is if withdraw amount is greater than your balance, go to the while loop. The while loop should get a new input and check if new input is greater than balance,...

While loop won't exit Java

java,loops,while-loop,exit
I'm entering a huge number and adding each line of numbers to the string "hold". Once there's nothing left to read it should exit the while loop and turn the string to a BigInteger. It will run through the loop till there is nothing left then nothing happens. It doesn't...

Understanding while in python

python,while-loop,nested
Good night, I have some idea about while functionality but I want to understand the why the variables inside its body refresh new values for the variables outside while body. Is something intrinsic of python? It was designed to be like that? num = int(input("Type a number: ")) while (num...

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 to format code so while loop is triggered C

c,while-loop,formatting,boolean-logic
So I have two while loops. The outer most one does not loop back the way I want it to. I first tried: #define true 1 #define false 0 But then set it to what I did below. My problem is that when I run the program, it terminates after...

How do I format the logic for 3 conditions and use a previous condition as well?

java,loops,if-statement,while-loop,logic
NOT ASKING FOR ANYONE TO WRITE THE PROGRAM FOR ME I am having trouble understanding how to setup the logic for a program given these following conditions: For every day late up to and including 7 days, the late fee is $0.10/day After 7 days, for every day late up...

Not entering while loop? [closed]

c++,while-loop,mergesort,insertion-sort
[EDIT] - Nevermind, this is a really dumb question I'm currently trying to create a program that will basically tell me when insertion sort takes a longer time than merge sort for given a, b and n (in this case, successive powers of 2). This is what I have so...

Can someone help me explain this code that is converting decimal fractions into a binary?

python,while-loop,binary,floating-point,decimal
Can someone help me explain this code that is converting decimal fractions into a binary? Convert the decimal fractions into a binary form: x = float(raw_input('Enter a decimal number between 0 and 1: ')) p = 0 while ((2**p)*x)%1 != 0: print('Remainder = ' + str((2**p)*x - int((2**p)*x))) p +=...

Square root algorithm in python [duplicate]

python,while-loop
This question already has an answer here: Is floating point math broken? 18 answers I am doing this in python with while loop. It's not terminating. x = 2.0 ans = 0 while ans**2 != abs(x): print (ans) ans = ans + 0.001 if ans**2 == abs(x): print(ans) ...

While loop w/ if statement won't follow sucesive if statements

java,string,if-statement,while-loop
Im doing an exercise I found on the internet to simulate the game "nim". The idea of the game is to get the other player to pick up the last item. The problem I am having is after player 1 makes a selection of which pile to pick from and...

tiered while loops with multiple outputs

list,loops,python-3.x,while-loop
I am trying to learn about arrays. I know that python has lists, not arrays, but the idea is the same. I have a list of lists setup like an array, and I am trying to modify them for random art fun, but I can only get one resulting random...

PHP While loop Notice: Undefined offset

php,while-loop
I am fixing an existing PHP code I get error Notice: Undefined offset: 6 The PHP code will look like below. It is a big while loop. Here I just show the main section. $data = Array ( [0] => 1 ) $data2 = Array ( [0] => 1 [1]...

checking if list has only letters . Python

python,list,function,while-loop
could you help with the below code? I can't seem to get it to run. I'm new to python so would appreciate some tips. Also, is there a way to check if the list has only letters? THanks! import random x = random.choice([9, 10]) def loop(): if x < 10...

Unexpected behavior from “fgets” in a while loop

c,osx,while-loop,fgets
I'm trying to read a file line by line using fgets, but its not working. Here is my code: #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LINE_SIZE 500 int main(int argc, char const *argv[]) { char *line; FILE *arq; //abre o arquivo para leitura if ((arq = fopen (argv[1], "r"))...

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...

While loop keeps printing out and not reading the next line

c++,printing,while-loop
This is my first simple program. It keeps printing out Guess what it is. non-stop and doesn't even ask for user input. (the next line of code.) What is my mistake? #include <iostream> #include <string> using namespace std; int main() { string userName; cout << "Hello there.\n"; cout << "My...

Ending While loop with blank line(Enter key) inside SwitchCase

java,while-loop,switch-statement,blank-line
*amended input scan I'm trying to end a while loop with enter key/blank line Test codes below works fine. Scanner scan = new Scanner(System.in); String line; while ( (line=scan.nextLine()).length() > 0) { System.out.println(line); } However, when I integrate it within my main program(while loop placed within int switch case within...

How to make sure to draw two different random cards [closed]

python,loops,random,while-loop
I have written code that should draw two different cards. However, I am not sure how I should end the while statement. Should I use break or continue? The while statement is there to make sure you don't draw two of the same cards. import random card_values = ["the Ace",...

How many times are primitive data types allocated inside loops?

c++,while-loop,allocation,variable-declaration,value-initialization
Here's an example: while (i < 10) { int j = 1; string k = "hello."; } j is a primitive data type and k is an object. According to Do built-in types have default constructors?, So non-class types (including fundamental types, array types, reference types, pointer types, and enum...

2 while loops follow one another? [closed]

python,while-loop
Is it possible if I want to make 2 while loops follow each other. For ex, after the 1st loops end, the 2nd loops begin. And could I insert a string (with print command) in the middle? I used python 3.4.3...

Matlab: For loop with window array

arrays,matlab,math,for-loop,while-loop
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...

Looping distinct values from one table through another without a join

sql,sql-server,tsql,while-loop
I know looping is not ideal in SQL, but I couldn't think of another way of doing this. I want each distinct row from this Table 1 to have each distinct date and hour produced on Table 2. In other words, Table 2 has the dates between 05/01/2014 through 04/30/2015,...

Calculating time for any sum to double, at a given rate of interest compounded annually

c++,while-loop,int,double
I was trying to write a program that calculates the time it takes for any sum of money to double at a given rate of interest compounded annually. When I run this program, I have found that the loop is not exiting the counter is incremented endlessly with the sum...

how can I be more efficient

matlab,for-loop,indexing,while-loop
How can I be more efficient in the following Matlab code? use a while loop? I would have to continue adding more if syntax for my purpose. Any help would be much appreciated. TimeLagM = 6;2;3;1;2;10;25;60;2;5;10;80;24;1;2;3; p=0; count=zeros(length(TimeLagM),1)); for i=4:length(TimeLagM) if TimeLagM(i,1)>30 count(i,1)=count(i,1)+0; elseif TimeLagM(i,1)==30 count(i,1)=count(i,1)+1; elseif TimeLagM(i,1)<30 p=TimeLagM(i,1)+TimeLagM(i-1,1); if...

My While True loop is getting stuck in python

python,while-loop,raspberry-pi,infinite-loop,raspbian
Hello I have been working on an infinite While True loop for the main file in my python code. I am working on a Raspberry Pi and my goal is that whenever one of the GPIO Pins senses an input it will print out a string. However When I push...

While loop running incorrect number of times

java,random,while-loop,boolean
I am having trouble with a while-loop, as the if statement is meant to check if the button is empty if not repeat. However if the whole if statement is in a while-loop it reveals about 4 buttons after running the code for the first time. case HINT: Random random...

beginner :While loop not working as it should

c++,loops,vector,while-loop
I am still a beginner and I am learning from a book. There was a drill that asked me filter input based on a vector of filtered words and if it was one of them it outputs "bad word" Here is the drill exactly as in the book. Try This...

trying to get a running time stamp on Qt

c++,qt,while-loop
I am trying to keep a running time stamp every so many milliseconds. This will eventually be attached to a temperature reading. Right now the time stamp is only displaying after the rest of my program has run and I need it to populate in real time. My updated code...

set a variable to only accept certain strings on python and break while loops using if/else [closed]

python,if-statement,while-loop,except
I'm currently writing a code that needs to be repeated but only if the user wants it to be repeated.I have put the code in a "while True" loop and tried to use if statements to repeat the code if the user enters "yes" or break the loop if the...

Beginner While loop error in MySQL

mysql,loops,while-loop
I have looked at various guides on MySQL WHILE Loops and still can't figure out what I am doing wrong. mysql> DELIMITER $$ mysql> CREATE PROCEDURE insertRooms() -> BEGIN -> DECLARE nRoom INT DEFAULT 101; -> WHILE nRoom < 109 DO -> INSERT INTO simple_room (room_number) VALUES nRoom; -> SET...

Updating jTextArea in while loop

java,swing,while-loop,jtextarea,updating
I am having a problem writing/updating the textarea. I am getting a value from the readtemp function, and i can see the result after calling the system out function, but nothing appears in the Textarea. What could be the problem? private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { URL temp; try { temp...

Nested foreach loop in a While loop can make the condition for the while loop go over?

php,loops,foreach,while-loop
Here is a little background on what I am trying to create. I am creating a function called getNextBilling($dateStart,$dateCount = 20) You give it a period length which is the days you want someone to be billed $test->period = '2,5,15'; it takes a starting date which I have assigned on...

How to swap digits in java

java,for-loop,while-loop
I am trying to practice java over the summer and i'm stuck on this problem. I need to swap the 2 letters in a integer in java. For example in my main method I make a method called swapdigits and have my parameters as 1432. The program should swap the...

Timed while loop not terminating [duplicate]

java,timer,while-loop,timertask
This question already has an answer here: Loop doesn't see changed value without a print statement 1 answer Running this code, I would expect it to increment the test variable for 5 seconds and then finish. import java.util.Timer; import java.util.TimerTask; public class Test { private static boolean running; public...

Repeating function call inside a while loop

c++,while-loop
I have a function called move() which I placed inside a while loop. This function lets the user choose an integer from 1 to 4 and returns that number. The while loop exits the loop if the function returns 3 or 4. This is my code in the main function....

Ruby post match returning Nil.. like its supposed too

ruby-on-rails,ruby,string,while-loop
My while loop is busted somehow.. I get this error: `block in scrape': undefined method `post_match' for nil :NilClass (NoMethodError) Its returning nil like its supposed too after going through the string, and it populates the array like its supposed too, but the last time it hits the .post_match it...

How to write my program without loops

matlab,function,math,for-loop,while-loop
I'm attempting to write the following program without any for or while loops: function [B] = check(A, k) B = []; [nrow ncol] = size(A); for i = 1:nrow for j = 1:ncol if mod(A(i,j),k) == 0 B = [B;A(i,j)]; else B = [B;A(i,j)*k]; end end end Basically this program...

Incorrect output from while loop

c,while-loop
This function asks for an integer between loLimit and hiLimit and allows the user to safely enter it. It keeps asking until the user enters a number in the legal range. Then it returns the legal number. The correct output should be: Please enter an integer between 32 and 127:...

Generate list of 200,000 hashes and save to file

python,while-loop
I wrote up this quick script to generate 200,000 hash random values and save them to a file, but I'm getting this error when I run the file: "TypeError: expected a character buffer object" on line: file_.write(hash) import random hash = random.SystemRandom() file_ = open('output.txt', 'w') count = 0 while...

Looping through a Vector

arrays,r,loops,vector,while-loop
I am using Rstudio and trying to create a function that will loop through a vector and perform a calculation with a while condition. The function should then return a data frame with the entered vector in one column and the number of iterations it took to satisfy the while...

Php code does not come out from MySQL Database properly

php,mysql,while-loop,phpmyadmin,echo
I was try to loop PHP CODE data from MYSQL database, but it looks different when it's echo'd out. HERE IS MY PHP CODE: <?php mysql_connect("localhost","root",""); mysql_select_db("myweb"); ?> <table width="100%" border="1"> <?php $query=mysql_query("SELECT * FROM right_widgets ORDER BY right_widgets_id ASC"); while($rows2=mysql_fetch_assoc($query)) { $right_widgets_id=$rows2['right_widgets_id']; $func_name=$rows2['func_name']; $active_status=$rows2['active_status']; ?> <tr> <td><?php echo $func_name;...

Run PHP function in While Loop

php,function,loops,while-loop
I'd like to run a function within a While loop. Unfortunately, it works but not quite as desired. My goal is to read out from a CSV file, each line and is stored in the MySQL database. This also works flawlessly. In addition, however, I want to let miteinpflegen a...

Change if statement from variable [closed]

c#,if-statement,for-loop,while-loop
Not sure if the question is correct, but here is what I am trying to accomplish. I am running a for-loop in which i want to change the if-statement in each loop. Here is the example: for(int i=0;i<3;i++){ int currentField = field; var context1=currentField; int curprogr=0; switch (i){ case 0:...

Why this while loop cannot print 1,000 times per seconds?

java,loops,time,while-loop
The following Java method is meant to print the number i by nLoopsPerSecond times per second for seconds seconds: public void test(int nLoopsPerSecond, int seconds) { double secondsPerLoop = 1.0/(double)nLoopsPerSecond; long startTime = System.currentTimeMillis(); long currentTime; int i = 0; while ((currentTime = System.currentTimeMillis()) < startTime + seconds*1000) { System.out.println(i++);...

CSV export only heading Arrays not Data

php,mysql,csv,while-loop
I'm Trying to export & download csv file containning mysql records using following code; header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=DepReport_'.$from.'_'.$to.'.csv'); $output = fopen('php://output', 'w'); fputcsv($output, array('Reference', 'Depart Date / Time', 'Depart Terminal', 'Depart Flight' ) ); $i = 2; while($rows = mysql_fetch_array($result)) { fputcsv($data[$i], array($rows['ReferenceNo'], date('Y-m-d',strtotime($rows['DepartDate'])).' '.$rows['DepartTime'],...

How to generate a random number with fixed length only with 0's and 1's and a fixed amount of 1's?

php,loops,random,while-loop,numbers
I did some research, but didn't found any solution for my question. What I want to archive: Generate a random number out of 0's ($min) and 1's ($max), but with a fixed amount ($many) of 1's in the random number. The random number should have a length of 6 as...

while loop is not breaking even if the condition is satisfied

c,loops,while-loop,iteration
I have created a program to print armstrong number, but the inner while loop is not breaking, it should break when the value is 0, but it is going into continuous loop. Can anyone tell me what's wrong in my program. Is this the correct behaviour of compiler. #include<stdio.h> int...

While loop inside a while loop from PDO query

php,while-loop
Consider a situation where you have a mysql table FLAGS with a random amount of rows ID Language Flag1 Flag2 Flag3 Flag4 1 dutch flanders_flag.png dutch_flag.png 2 french wallonia_flag.png french_flag.png morocco_flag.png 3 english england_flag.png ireland_flag.png america_flag.png scotland_flag.png if i want to query these rows and put them into my html...

using getopts did not get the input value

bash,while-loop,getopts
I am running the below script, but it looks like the $filename or $srvname did not get the input value. say for eg: ./test.sh -n abcd.net gives the output echo 'Filename or node name must be defined.' it means that, the $srvname did not get the value "abcd.net", please advise...

While statement has no body?

java,loops,syntax,while-loop
I have a number of statements in one procedure like this: while( x + ++flips < 8 && board[x + flips][y] == opponent ); The (standard "Oracle") compiler is returning the error: "While statement has no body." Is this required by the language specification, or is it compiler specific? Is...

How are the results for count different in all these three cases?

python,for-loop,while-loop,break
Code 1: iteration = 0 count = 0 while iteration < 5: for letter in "hello, world": count += 1 print "Iteration " + str(iteration) + "; count is: " + str(count) iteration += 1 Code 2: iteration = 0 while iteration < 5: count = 0 for letter in...

Ruby .each method on Array from split string

arrays,ruby,while-loop,split,each
I'm having trouble using the .each method on an array that results of a string.split def my_function(str) words = str.split return words #=> good, morning return words[words.count-1] #=> morning words.each do |word| return word end end puts my_function("good morning") #=> good With any multi-word string, I only get the 1st...

Repeat a sound/action every certain time

python,date,time,while-loop,repeat
I'm trying to write a Python program that reproduces a sound every certain hour, but it doesn't really work. When I test the code and the specified time comes, it will keep repeating the sound forever. Here is the code: import os from datetime import datetime now = datetime.now() currentHour...

loop for file location until file exists in bash

bash,file,loops,while-loop,echo
I have created this function: function promptFile() { while true; do read -p "Please provide a full path [q to quit]: " file if [ $file == q ]; then echo "Exiting.." return 1 fi if [ ! -f $file ]; then echo "File does not exist, please try again"...

Javascript play multiple audio in loop

javascript,audio,while-loop
I create html and javascript for play sound number : <audio id="audio_0" src="0.wav" ></audio> <audio id="audio_1" src="1.wav" ></audio> <audio id="audio_2" src="2.wav" ></audio> <audio id="audio_3" src="3.wav" ></audio> <audio id="audio_4" src="4.wav" ></audio> <audio id="audio_5" src="5.wav" ></audio> <audio id="audio_6" src="6.wav" ></audio> <audio id="audio_7" src="7.wav" ></audio> <audio id="audio_8" src="8.wav" ></audio>...

Getting my program to go back to the “top” (if statement) (Java)

java,if-statement,while-loop,leap-year
I have a program to calculate leap year, however, it only works past about the year 1750 so I want my user to only be able to input numbers past 1750. System.out.println("Enter a year after 1750:"); leapYear = in.nextInt(); if(leapYear<1750){ System.out.println("You have entered a year before 1750, please try again...

While Loop increment issue

python,while-loop
Right now I am trying to make a simple program to separate the javascript links of a website but I'm running into issues with a while loop. Here would be an example of an input: 001_usa_wool.jpg 002_china_silk.jpg 003_canada_cotton.jpg 004_france_wool.jpg done A simplified version of my code with just 3 parts...

How do I get my logic in this Java program to make my loop work?

java,if-statement,while-loop,int,logic
I've made this java program to find the two smallest integers as inputted by the user. I think I'm pretty much just about there except there is one issue with my logic. I'm not sure what to set values: int min, min2; to where the rest of my program would...

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....

while loop in table [closed]

php,sql,while-loop,user
I have this problem with this while loop. I want to make a table where an administrator can see users and delete them. So I want this into a table. I have tried some echo's like: echo <table>, echo <td>, echo </td>, echo </table>. Unfortunately nothing of this al works....

Can't get my function to run more than once and break my code

javascript,while-loop
I'm trying to run this function until the player or the computer wins 5 times. Without the while loop, it runs one time and everything works fine. As soon as I add a while loop, the function still runs only once and it gives me an undefined return. function playToFive()...

Javascript alert wont dismiss (while loop)

javascript,html,while-loop
I'm trying to make a "How many fingers are you holding up" page, if i input 1-5 in the box, it works, but if i input more than 5, the alert wont disappear, can anyone help me with this? Sorry for the noob question Any help will be greatly appreciated!...

counting characters in the input with while loop

c,loops,while-loop,char,eof
I wrote a simple c program to count number of characters #include <stdio.h> main() { long nc; nc = 0; while (getchar() != EOF) ++nc; printf("%ld\n", nc); } This program is not printing me the characters. On testing different cases, I found that I am stuck in an infinite while()...

Displaying loop in JOptionPane

java,while-loop,joptionpane
I'm a beginner in Java programming, and I have an assignment on while loops. The assignment was to have windows open up with the numbers 1-10 on display. The first two, I got down. The third one was to have the user enter a number 'x', and the next window...

Combine Grep and Regex?

ruby,regex,input,while-loop,stdout
Have a list of smaller network elements that i am trying to list in the stdout. My small little script works up until the regex, after i get prompted what i want to search for it lists the whole line. Example: Please Enter a Region Input: Bei Output: ipc-bei640-r-br-01 ipc-bei640-r-br-02...

Python 2.7: While loop, can't break out

python,sockets,python-2.7,while-loop
I'm new to programming and to this website so I hope I can clarify what I'm trying to do. I have a loop I'm trying to break out of if I send the string quit. It seems to just keep going. Please help! import socket Home = '10.0.0.5' #ipaddr Port...

switch does nothing on Decompiled Android Source

android,for-loop,while-loop,apk,decompiler
switch(paramMotionEvent.getAction()) { } do { for(;;) { return super.onInterceptTouchEvent(paramMotionEvent); this.prevX = MotionEvent.obtain(paramMotionEvent).getX(); } }while(Math.abs(paramMotionEvent.getX() - this.prevX) <=this.touchSlop); return false; } } Hi, I decompiled a few APK files. While analyzing those source code, I found weird lines similar to above code. Why does the switch do nothing? In addition, I...

while(*s++=*t++) is equivalent to which expression?

c,loops,while-loop
A. while (*t) *s++ = *t++; B. do { *s = *t++; } while (*s++); C. while (*s) *s++ = *t++; D. do { *s++ = *t++; } while (*t); The answer is B, why others are wrong?...

C code error: expected ';' before '{' token [closed]

c,while-loop
When I run the code, I get this error : In function 'print': error: expected ';' before '{' token I'm using gcc compiler, I can't really find what I'm missing here: Code: #include <stdio.h> void print(char *C) { int i = 0; While(C[i] != '\0') { printf("%c",C[i]); i++; } printf("\n");...