while

Loop with a while

Very basic question.. but I'm missing the point.. I have this data on my table: ID SITEID SECTION 1 1 posts 2 2 posts 3 1 aboutme 4 1 contact 5 2 questions The output is an array. I can't change it. I want to make this output on php with a single for loop with that array: <h1> sections for site 1 </h1>...

how to change the while loop condition depending on stuff?

by this question what i mean is that if, by example, someone's username is "bob" then the while loop condition will be ($i < 10), and if the username is something else then the while loop condition will be ($i > 10) if($username == "bob") { //make this while loop condition: ($i < 10) // it means: while($i <10){ so stuff} } else { ...

I need to know inside of "while(fscanf != EOF){blah}" if the next fscanf is going to return EOF-- because I need to keep executing portions of the {blah} code after fscanf hits EOF. ?

I've got some code executing in a while(fscanf != EOF) loop. However, even when fscanf has finished executing, I need to keep running that code until some conditions are met. I mean I guess I could copy/paste the code to outside the while(fscanf) loop, and only use global variables, but that seems messy. Surely someone has encountered so...

Advanced switch statement within while loop?

I just started C++ but have some prior knowledge to other languages (vb awhile back unfortunately), but have an odd predicament. I disliked using so many IF statements and wanted to use switch/cases as it seemed cleaner, and I wanted to get in the practice.. But.. Lets say I have the following scenario (theorietical code): while(1) { ...

Windows Workflows - While Activity for creating multiple tasks not working

I am using a while activity for creating multiple tasks for a workflow. The code is executed fine and the task is created when the loop runs only once. But when the loop runs twice or more, only one task is getting created. Also the WF status shows as Error Occured. All I want to do here is create multiple tasks (no of tasks depends on ...

Can I have a CASE statement within a WHILE loop?

This is what I'm doing: while (@counter < 3 and @newBalance >0) begin CASE when @counter = 1 then ( @monFee1 = @monthlyFee, @newBalance = @newBalance-@fee) when @counter = 2 then ( @monFee2 = @monthlyFee, @newBalance = @newBalance-@fee) END @counter = @counter +1 end I get this error: Incorrect syntax near the keyword 'CASE...

For vs. while in C programming ?

There are 3 loops in C: for, while, do-while. What's the difference between them? For example, it seems nearly all while statement can be replaced by for statement, right? Then, what's the advantage using while? ...

PHP while array

Hello <?php $airports = array('LED','DME','SVO','VKO','AER','KRR','IKT','KGP','KHV'); if ($content = getData('LED')) { return $content; } Need to go on line through the array until the content is not empty! How? Sry for bad english ...

Rotating do while PHP

Hello all! Well I have unusual question I think. I am making a web site and the products must be shown as a line I will past a link for better understanding. http://partyclub.mdkbg.com/products_carbonated_mix.html Clicking the bottle in the right will change the products to the next. But if you keep clicking will see that when the end...

Which is faster in SQL, While loop, Recursive Stored proc, or Cursor?

Which is faster in SQL, While loop, Recursive Stored proc, or Cursor? I want to optimize the performance in a couple of spots in a stored procedure. The code I'm optimizing formats some strings for output to a file. ...

Problem with "while" in Java

I'm trying out several exercises from a Java programming book. I have the code below: import java.io.*; import java.util.Scanner; public class Ex420 { public static void main( String args[] ) { String employeeName = ""; double workHours,excessHours, hourlyRates, grossPay; Scanner input = new Scanner( System.in ); while ( emp...

Perl: Multiple global "or"-separated regex conditions in while block leads to an infinite loop?

Hi all, I'm learning Perl and noticed a rather peculiar quirk -- attempting to match one of multiple regex conditions in a while loop results in that loop going on for infinity: #!/usr/bin/perl my $hivar = "this or that"; while ($hivar =~ m/this/ig || $hivar =~ m/that/ig) { print "$&\n"; } The output of this program is: th...

Java while loop in threads

I have written a program in Java which has 5 threads. In the run() I have a while loop which will loop over and over and this loop will loop a lot of times. While the program is running, it is gradually eating ram bringing the program to a crawl. Is there anyway I can stop it eating all my ram? Edit: Actually just thinking about it, i...

How to get out of a try/except inside a while? [Python]

I'm trying this simple code, but the damn break doesn't work... what is wrong? while True: for proxy in proxylist: try: h = urllib.urlopen(website, proxies = {'http': proxy}).readlines() print 'worked %s' % proxy break except: print 'error %s' % proxy print 'done' It'...

SQL loop problem

Hi guys, I have a problem, I hope somebody out there can help. I'm not really good at sql programming so I need help from u guys. Here's my problem, I have customercode that has possible of 2 or 3 addresses. sample: cust1 address1 cust1 address2 cust1 address3 cust2 address1 cust2 address2 I want to generate a report in .net to...

while(list($key, $value) = each($array)) vs. foreach($array as $key => $value)?

Recently I experienced this weird problem: while(list($key, $value) = each($array)) was not listing all array values, where replacing it with... foreach($array as $key => $value) ...worked perfectly. And, I'm curious now.. what is the difference between those two? ...

Is while True: a suitable way to repeat a block until an accepted case is reached?

Is while True an accepted method for looping over a block of code until an accepted case is reached as below? Is there a more elegant way to do this? while True: value = input() if value == condition: break else: pass # Continue code here. Thank you for any input. ...

PHP sum values of a whilefunction

Hello guys, we've codeded this PHP-Script: function price($id) { $ergebnis = mysql_query("SELECT * FROM preiszuordnungen where id=$id"); while($row = mysql_fetch_object($ergebnis)) { //Wenn grundpreis dann färben if($row->typ=="grundpreis") { ...

'if' inside 'while' statement in php

I have this bit of code which loops through an array and echos out the result to the page thus: while($row = mysqli_fetch_array($result)) { echo '<tr><td><a target="_blank" href="' . $row['url'] . '">' . $row['name'] . '</a></td>' . '<td>' . $row['provider'] . '</td>' . '<td>' . $row['media'] . "</td></tr><br />\n"; } ...

MYSQL: Instead of using SELECT statements in a while loop - what are my options?

I have a table which contains a list of categories and and another table which contains a list of products in each category. e.g. CatID | Cat_Name ---------------- 1 | Books 2 | CDs and ProductID | Product_Name | CatID ------------------------------------ 1 |The Bible | 1 2 |The Koran | 1 ...