while

Java- && doesn't seem to be working in a while loop...

NEVER MIND- IT WAS MY OWN DUMB MISTAKE, CONFUSED THE VARIABLES I have the following while loop: while (((pi.getFunds() - rmiPrice) > 0) && (rmi.getInventory() > 0)) { } pi.getFunds() is a double that represents how much money a fictional object (pi) has, rmiPrice is a double that represents a price of a product (rmi) that pi wants ...

PHP multidimensional arrays in generating question summaries

The purpose of this question is to find the best way to print data out of PHP multidimensional arrays. How can you complete the following procedure below? I have the following arrays array1['id']['title'] and array2['id']['tags'][] The arrays have been generated by the function pg_fetch_array. This allows you refer to each value ...

Canceling a While loop prematurely.

I'm using a While loop that loops a certain number of cycles (1-576) based on a value entered by a user. It's activated by the user clicking a "Start" button, But I would like it to be able to be canceled using, preferably, the "Escape" key. However, when the loop is going I can't get the program to recognize any keypresses. Private Su...

Print out the answers for a question by PHP

How can you use the following sample data either with a foreach or while -loop? I get the following sample data by running $answers = pg_fetch_all ( $result );. Sample data [0]=> array(3) { ["answer"]=> string(7) "This is the answer" ["username"]=> string(5) "roope" ["was_sent_at_time"]=> string(26) "2009-...

JavaScript - Are loops really faster in reverse...?

I've heard this quite a few times. Are JavaScript loops really faster when counting backward? If so, why? I've seen a few test suite examples showing that reversed loops are quicker, but I cant find any explanation as to why! I'm assuming it's because the loop no longer has to evaluate a property each time it checks to see if it's finis...

Any reason to replace while(condition) with for(;condition;) in C++?

Looks like while( condition ) { //do stuff } is completely equivalent to for( ; condition; ) { //do stuff } Is there any reason to use the latter instead of the former? ...

PHP round numbers, add decimal numbers

I'm using a simple loop to echo back some numbers <?php $inc = 0.25; $start = 0.25; $stop = 5.00; ?> <?php while($start != ($stop + $inc)){ ?> <option><?php echo $start ?></option> <?php $start = $start + $inc; ?> <?php } ?> However 5.00 appears as 5 and 4.50 appears as 4.5 How would i get this script to display 5.00, 4.00, 3.00, 3...

Timer & TimerTask versus Thread + sleep in Java

I found similar questions asked here but there weren't answers to my satisfaction. So rephrasing the question again- I have a task that needs to be done on a periodic basis (say 1 minute intervals). What is advantage of using Timertask & Timer to do this as opposed to creating a new thread that has a infinite loop with sleep? Code snip...

java nested while loop using readline

I'm confused. I'm trying to loop though 2 files looking at the first token in every line of the first file and comparing it to the third token of every line of the second file. Here is the logical structure in the form of a nested while loop: BufferedReader reader1 = new BufferedReader(new InputStreamReader(new FileInputStream(fromFile1...

Replay tic tac toe game

So I am trying to program a way to replay a tic tac toe game after someone wins, loses, or ties. So basically my attempt to get replay to work, doesnt work. If player 1 won and I type 1 to replay, it would ask player 2 for their input A basic outline of my code looks like this: do { set entire 2d array to '*' do { ...

For loop in while loop

Hi, can I put a for loop in while loop? For example: while($end = 1) { for ($i = 0; $i < count($match); $i++) { $mathcas = $match[$i][1]; } } Thanks. :) ...

PHP: display entries from Database in groups of five?

Hi, Is it possible and if so, how can I do it, to select all entries in a table in my database and then display five results at the time in one group. Meaning: A example is that I've 15 records total in my database, then I want to present my data like this: <div class="1-5">Record[1], Record[2], Record[3], Record[4], Record[5]</div> ...

python: how can i avoid " list index out of range" in this simple while loop

my L1 array contains numbers like 0.029999999999999999 which i want to print off as 0.03 my code works, but gives an error at the end because the last count is out of range. i understand why it breaks, but dont know how to fix it. thanks count = 1 while L1: print "%.2f" %L1[count] count = count + 1 ...

Is it possible to have a while loop in c++ that makes the check in the middle of the loop instead of the beginning or end?

I want to have a while loop do something like the following, but is this possible in c++? If so, how does the syntax go? do { //some code while( expression to be evaluated ); // some more code } I would want the loop to be exited as soon as the while statement decides the expression is no longer true( i.e. if expression i...

how can i controll while loop into another while loop

Suppose I have a while loop like: $sql = mysql_query("SELECT * FROM tablename"); while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $sql_2 = mysql_query("SELECT * FROM secondtable WHERE id != $id "); while($ro = mysql_fetch_array($sql_2)){ $id2 = $ro["id2"]; echo $id2; } } then if first query return 5 results i....

Line Break within echo in a while loop

Quick question, again, I'm sure this is ridiculously simple but I don't see what I'm doing wrong! while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']} </a>"; } This produces all my links to be stacked up one after the other. I want to order them in...

While loop example

x = y // 2 # For some y > 1 while x > 1: if y % x == 0: # Remainder print(y, 'has factor', x) break # Skip else x -= 1 else: # Normal exit print(y, 'is prime') This is an example for understanding while loop in a book I'm reading, I don't quite understand why a floor division and then y % x? Can someone please...

SQLite Flow Constructs in SQL?

With MSSQL, I can mix in case, if...then, and while constructs in my SQL code. Is anything similar available for SQLite? I have not seen anything on "mixing procedurally" with SQLite, anywhere. Thanks. ...

I am writing a function to do "while" , but why error?

I am writing a function to do "while" to count the numbers of alphabetic and digits in a text file. I would like to seperate it to 2 functions of 2 "while". But it error after I create the first function. What's wrong of it? #include "stdafx.h" #include "stdlib.h" #include "ctype.h" void countDig (FILE* input, char num,...

Find out for how long the script was running for in seconds?

I have a script which runs in a 'while' cycle. I need to determine for how long the script was running for and if it is over 10 seconds terminate it. The code I wrote returns weird decimal values (one second it might be '5.342...' and other it might be '903.322...'). Can someone tell me how can I achieve that? $timer = microtime(false);...