while-loops

looping loops in ruby (noob)

n = 0 m = 40 o = 0 while n < m n = n + 1 end while n = m o = o + 1 n = 0 end With that code, what would be the best way to make it so once it went through the second loop it would go back through the first??? Any help for this beginner is welcomed. :) ...

Nested loops always confuse me

So I have a loop to be nested inside another loop based on two queries. I have the first loop working fine- $sql_categories = mysql_query("SELECT * FROM $categories_table"); $results = mysql_query("SELECT * FROM $events_table"); while ($num_rows = mysql_fetch_assoc($sql_categories)) { extract($num_rows); echo "<h2>...

While loop with try catch fails at bad cin input

I can't seem to figure out why this falls into a loop after getting non-int input. I've tried cin.flush(), which doesn't seem to exist, cin.clear(), which seems like it should work, even cin.sync() after reading someone else post about it working, but didn't seem to make much sense. Also tried cin.bad(). Thank you very much for any help...

python basic while loop

I have another newbie Python question. I have the following piece of code that I have a feeling is not written as pythonic as it should be: rowindex = 0 while params.getfirst('myfield'+rowindex): myid = params.getfirst('myfield'+rowindex) # do stuff with myid rowindex+=1 The input to this script is an ...

Simple C++ input from file...how to?

I have a file: P 0.5 0.6 0.3 30 300 80 150 160 400 200 150 250 300 T r 45 0 0 s 0.5 1.5 0 0 t 200 –150 . . . When I read in 'P' I know that 3 floats will follow. That will be followed by a finite number of X and Y coordinates. The number will vary until a 'T' is reached which I have to recognize. Then there could be an 'r', 's' or 't...

While loop never ends

I'm working with bash and I'm trying to do something like this: A=1 while [ $A=1 ]; do read line echo $line | grep test >/dev/null A=$? echo $A done This script never ends even when the grep finishes successfully and A is set to 0. What am I missing here? Below is a sample of the output. $ ./test.sh asdf 1 te...

Java While-Loops

So while rewriting some code, I came across something along the lines of: Method 1 while ( iter.hasNext() ) { Object obj = iter.next(); if ( obj instanceof Something ) { returnValue = (Something) obj; break; } } I re-wrote it as the following without much thought (the actual purpose of the re-write was for...

Infinite While Loop in Java

Hey there! I'm trying to do some data input validation but I haven't been able to figure it out. I'm getting an infinite while loop in when I try to validate if the first character entered is a letter. . . . Thanks for your help! public class methods { public static void main(String args[]) throws IOException { String...

While loop value test

I have an array of objects that contains a key value with true or false. These values start as false but switch to true on completion of their work. I was looking to determine when all the values had completed i.e. all switched to true. Is there a deviation(logic below) on a while loop with a test if statement that may solve this. bas...

Bash while loop calling a Python script

I would like to call a Python script from within a Bash while loop. However, I do not understand very well how to use appropriately the while loop (and maybe variable) syntax of the Bash. The behaviour I am looking for is that, while a file still contains lines (DNA sequences), I am calling a Python script to extract groups of sequences ...

returning out of for-loop

I'm pretty new at python and I was wondering if this: def func(self, foo): for foo in self.list: if foo.boolfunc(): return True return False is good practice. Can I return out of a loop like the above or should i use a while-loop, like so? def func(self, foo): found = false while(not found & i < len(self.li...

Will while(true) in a process of real time priority hang OS?

Will an application with an infinite loop hang the operating system if the application process has real time priority? Should I expect the same behavior on Linux, Windows and Mac OS? ...

FPDF Page Break Question

I am using PHP and FPDF to generate a PDF with a list of items. My problem is if the item list goes on to a second or third page, I want to keep the Item Name, Quantity and Description together. Right now, it will go to a second page, but it may split up all of the details for a particular item. PLEASE HELP! <?php require_once('auth....

PHP - While loop

print "<ul>"; foreach ($arr as $value) { echo("<li>" . $value[storeid] . " " . ($value[dvdstock] + $value[vhsstock]) . "</li>"); } print "</ul>"; Will output •2 20 •2 10 •1 20 •1 20 •1 10 I was wondering how I would adapt this loop so it outputs the total values for each &value[storeid] •1 50 •2 30 Thanks very much :) ...

What is the right way to stop an infinite while-loop with a Term::Readline-readline?

What is the right way to stop an endless while-loop with a Term::Readline::readline? This way I can not read in a single 0 #!/usr/bin/env perl use warnings; use strict; use 5.010; use Term::ReadLine; my $term = Term::ReadLine->new( 'Text' ); my $content; while ( 1 ) { my $con = $term->readline( 'input: ' ); last if not $con;...

PHP While Loops from Arrays

I have a table that contains members names and a field with multiple ID numbers. I want to create a query that returns results where any values in the ID fields overlap with any values in the array. For example: lastname: Smith firstname: John id: 101, 103 I have Array #1 with the values 101, 102, 103 I want...

PHP behaves weird, mixing up HTML markup.

Thanks for looking on this problem. I have a page that is totally valid page, and there is a PHP loop that brings in a <li> for each entry of the table. When i check this page locally it looks 100% OK, but when veiwing the page online the left side bar (which creates this markup is broken randomly mixing <div>'s and <li>'s and i have n...

How to exit a bash loop using ls?

I want to loop over a series of files in a directory in batches and then exit when the directory is empty. At $work 'myprog' is actually a program which processes (and archives) incoming email in a Maildir in batches of 100. I am after something simple I can put into cron. #!/bin/bash # Setup mkdir -p foo && touch foo/file_{1,2,3,4}....

Why does this while terminate before receiving a value? (java)

Here's the relevant code snippet. public static Territory[] assignTerri (Territory[] board, String[] colors) { for (int i = 0; i<board.length; i++) { // so a problem is that Territory.translate is void fix this. System.out.print ("What team controls ") ; Territory.translate (i) ; System.out.println (" ?") ;...

Adding the sum of numbers using a loop statement

I need serious help dividing the positive numbers and the negative numbers. I am to accumulate the total of the negative values and separately accumulate the total of the positive values. After the loop, you are then to display the sum of the negative values and the sum of the positive values. The data is suppose to look like this: ...