while-loops

How do I increment a variable so it chooses differnet lines from a text files in a While Loop.

I have a script im writing. Here is whats happening. There is a while loop. In the while loop is a variable which is constant to X. How do i make X change from line one, line two, etc for each cycle of the while loop and pull X from a .txt file. Everything is in root. Thanks ...

Grouping records from while loop | PHP

I'm trying to group down records by their priority levels, e.g. --- Priority: High --- Records... --- Priority: Medium --- Records... --- Priority: Low --- Records... Something like that, how do I do that in PHP? The while loop orders records by the priority column which has int value (high = 3, medium = 2,...

How to define and use Python generators appropriately

I want to define a generator from a list that will output the elements one at a time, then use this generator object in an appropriate manner. a = ["Hello", "world", "!"] b = (x for x in a) c = next(b, None) while c != None: print c, c = next(b, None) Is there anything wrong or improvable with the while approach here? Is ther...

Trying to set up nested while loops using a boolean switch

I'm trying to set up a while loop that will ask the user for the employee name, hours worked and hourly wage until the user enters 'DONE'. Eventually I'll modify the code to calculate the weekly pay and write it to a list, but one thing at a time. The problem is once the main while loop executes once, it just stops. Doesn't error out but...

Whats wrong with this while loop?

boolean r = false ; int s = 0 ; while (r == false) ; { s = getInt() ; if (!(s>=0 && s<=2)) System.out.println ("try again not a valid response") ; else r = true ; } The text never displays itself even when a 3 or a 123 is entered and the loop never terminates. Whats wrong here? ...

Is there a way to break out of a while loop before the original condition is made false?

Is there a way to break out of a while loop before the original condition is made false? for example if i have: while (a==true) { doSomething() ; if (d==false) get out of loop ; doSomething_that_i_don't_want_done_if_d_is_false_but_do_if_a_and_d_are_true() ; } Is there any way of doing this? ...

Java: "cannot find symbol" error of a String[] defined within a while-loop

Here's the relevant code: public static String[] runTeams (String CPUcolor) { boolean z = false ; //String[] a = new String[6] ; boolean CPU = false ; while (z == false) { while (CPU==false) { String[] a = assignTeams () ; printOrder (a) ; for (int i = 1...

showing surrounding page numbers

I've been doing some pagination recently and used the following: if ( $totalPages > $pagesToShow ) { $start = $pageNumber - floor($pagesToShow/2); $end = $pageNumber + floor($pagesToShow/2); while ( $start < 1 ) { $start++; $end++; } while ( $end > $totalPages ) { $start--; $end--; ...

Differences between a while loop and a for loop in PHP?

I'm reading an ebook on PHP right now, and the author noted that the difference between a while loop and a for loop is that the for loop will count how many times it runs. So take this: <?php for ($i = 1; $i < 10; $i = $i + 1) { print "Number $i\n"; } ?> But wouldn't this be the same as <?php $i = 1; wh...

Need Associated ID Added to a While Loop (php)

Been trying to get my head around while loops for the last few days but the code seems very inefficient for what Im trying to achieve. I'm assuming I'm overcomplicating this though nothing I've tried seems to work. Each topic in my forum can have related topic IDs stored in a seperate table. A post ID is also stored in this table, as th...

Need to convert this for loop to a while loop

Hi guys, I solved a problem recently. But I have this one piece of code where I dont utilize the for loop initialization and condition check. It looks a bit odd that way for a for loop. I want to convert it into a while loop. Please help me do it. I tried many times, but somewhere something is missing. for(;;current =(current+1)%n){ ...

using array_sum() in a while loop

Hi folks, I'm learning PHP. Having trouble understanding why this piece of code isn't working. In particular: why is the result of array_sum($x) (1596) greater than $cap? Perhaps I'm not understanding the nature of while loops, but it seems to me (looking at a print_r($x)), the loop should cut out a step before it actually does. <?...

How can I return a sql select into a sql variable

Hi, I'm trying to put the results of a SELECT into a variable and loop through the results to manipulate that data, all in the same stored proceedure... Here's what I have so far: DECLARE @i int @Result = (SELECT * FROM UserImport) SET @i = 0 WHILE @i < (SELECT Count(@Result) As Count) BEGIN /* Do Stuff */ END I know I'm way off...

Objective C "do - while" question

The example for one of the exercises in the book I am reading shows the following code: #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int input, reverse, numberOfDigits; reverse = 0; numberOfDigits = 0; NSLog (@"Please inp...

While loop: Output something different on every second result

Hi, I am running a plugin called Category Posts Widget for WordPress: http://wordpress.org/extend/plugins/category-posts/ It uses a while loop to display the names of all posts in a certain category. I want to get it so that there is a different class attached to the li tag on every second output. Here is the block of code for the plug...

[Java]Queue in while loop, cannot modify the value?

This is my code: Iterator it = queue.iterator(); while(it.hasNext()){ random = randNumber(1,2); if(random == 1){ queue.poll(); } else { queue.add("new"); queue.poll(); } } It gives me: Exception in thread "test" java.util.ConcurrentModificationException at java.util....

Timeout on Large MySQL Query

I have this code: $theQuery = mysql_query("SELECT phrase, date from wordList WHERE group='nouns'"); while($getWords=mysql_fetch_array($theQuery)) { echo "$getWords[phrase] created on $getWords[date]<br>"; } The query has 75,000 results, and every time I run the code I get an error. ...

Nested WHILE loops in Python

I am a beginner with Python and trying few programs. I have something like the following WHILE loop construct in Python (not exact). IDLE 2.6.4 >>> a=0 >>> b=0 >>> while a < 4: a=a+1 while b < 4: b=b+1 print a, b 1 1 1 2 1 3 1 4 I am expecting the outer loop to loop through 1,2,3 and 4. And I kno...

never ending loop : fatal error

my code- function create_id() { //global $myusername; $part1 = substr("Piyush", 0, -4); $part2 = rand (99,99999); $part3 = date("s"); return $part1.$part2.$part3; } echo create_id(); //this is printing fine. function isUniqueUserID($userIDToCheck) { $sqlcheck = "Select * FROM ruser WHERE userId...

C++ performance, for versus while

hello. In general (or from your experience), is there difference in performance between for and while loops? What if they are doubly/triply nested? Is vectorization (SSE) affected by loop variant in g++ or Intel compilers? Thank you ...