|
EDIT: I forgot to add the loop part of the second code.
Looking at the two code styles
while(some_loop_cont_val) { while(pre_x is not done) { //do action pre_x } //do action x }
and
while(some_loop_cont_val) { if(pre_x is not done) { //do action pre_x...
Started by Keand64 on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
Compare:
while(some_loop_cont_val) { if(some_det) { break; } } //"break"....
The second example commits two some useful functionality introduced by break / continue statements .
In the first example, the second while loop might actually 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 ...
Started by testkhan on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Sql = mysql_query("SELECT * FROM tablename"); $tmp = array(); while($row = mysql_fetch_array($sql WHERE id != $id "); while($ro = mysql_fetch_array($sql_2)){ $id2 = $ro["id2"]; echo $id2; } $tmp[] = $id = mysql_query("SELECT * FROM tablename....
|
|
I've seen both the blocks of code in use several different times, personally I have always used the first but my question is: is there a functional difference, and if there is what is it?
while (condition is true ) { // do something } do { // do something...
Started by Unkwntech on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
The while loop will check "condition" first; if it's false, it will never "do something." But the do...while....
If it should repeat the "do something" while the while loop checks the condition before doing anything the condition.
|
Ask your Facebook Friends
|
Hello
I have a while loop that goes through a table and I echo the results within it, I also have a while loop that looks at a image directory and I can output the paths to images. My problem is I want to output the image path in the other while loop ...
Started by Anders Kitson on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
The shoe image in your main loop:
while($row = mysql_fetch_array($results)){ $image = $row['image.
|
|
Sorry, I'm new to Java, so this question might be unclear.
I have been recently dealing with enclosing a try and catch statement in a while loop, because I wanted to make sure that getting input was enclosed from the rest of the program. I have come across...
Started by Mana on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
So if you use:
while (done = false) { // code here }
Then done is set to false and the....
In your code, if you replace while (!inputDone) with while(inputDone == false with false and is exactly identical to !done .
Of the value of x.
|
|
I've been looking at some code recently where the author used something similar to this (pseudo-code):
WHILE TRUE OpenAFile IF Failed BREAK ENDIF DoSomething IF NOT OK BREAK ENDIF ...etc... BREAK END WHILE
Arguments for using this design was speed (due...
Started by ColinYounger on
, 18 posts
by 17 people.
Answer Snippets (Read the full thread at stackoverflow):
Yes, especially....
You can say the same about any as clean as you get .
"IF" is just a nasty goto.
"END WHILE" is just a nasty goto.
} while(false); // or whatever it's written in VB
is a better alternative.
This is an infinite loop!
do { ...
|
|
I can't for the life of me see why I can not read the postPrioity outside the while loop. I tried "export postPrioity="500"" still didn't work.
Any ideas?
-- or in plan text --
#!/bin/bash cat "/files.txt" | while read namesInFile; do postPrioity="500...
Started by Mint on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
#!/bin/bash postPriority=0 while read of the pipe:
command | { while read line; do variable=value done # Here $variable exists echo $variable } # Here it doesn't
Alternatively....
Solution: Don't use cat , it's useless anyway.
And BashFAQ.
|
|
A customer recently performed static analysis of my employer's C codebase and gave us the results. Among useful patches was the request to change the famous do { ... } while(0) macro to do { ... } while(0,0) . I understand what their patch is doing (using...
Started by Commodore Jaeger on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
} while(0)
Even....
} while(0,0)
over
do { ...
Just a guess as to why they might suggest using
do { .. .
If you like your code making owl-y eyes at you, use while(0,0 this is intended to solve.
To be discovered by greater gurus than I.
|
|
In my ASP.NET MVC application, one of my actions is going to take a while -- it kicks off a sequence of other tasks. I'd like to report progress to the user. I want to display text -- I don't want a simple progress bar or spinner.
How should I go about...
Started by Roger Lipscombe on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
It has a comprehensive yet concise discussion of the problems, solutions, usability considerations and other interesting details... .
I started of writing a response but then I realized I should just redirect to the Progress Indicator AJAX pattern resource .
|
|
For() or while() - which is BEST?
for (i=1; i<a; i++) /* do something */
OR
i=1; while (i<a) { /* do something */ i++; }
Started by aks on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
For ....
For the while loop for and while loops are actually not.
If you're going to write a while loop that is equivalent, expression to be executed after each iteration) are all on one line.
This will do something a times.
At zero.
|