All Questions

409
votes
5answers
163380 views

Why is “while ( !feof (file) )” always wrong?

I've seen people trying to read files like this in a lot of posts lately. Code #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { char * path = argc > 1 ? a...
7
votes
9answers
9987 views

What is a NumberFormatException and how can I fix it?

Error Message: Exception in thread "main" java.lang.NumberFormatException: For input string: "Ace of Clubs" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at ...
97
votes
5answers
93256 views

A variable modified inside a while loop is not remembered

In the following program, if I set the variable $foo to the value 1 inside the first if statement, it works in the sense that its value is remembered after the if statement. However, when I set the sa...
177
votes
20answers
93962 views

Declaring variables inside or outside of a loop

Why does the following work fine? String str; while (condition) { str = calculateStr(); ..... } But this one is said to be dangerous/incorrect: while (condition) { String str = calcula...
122
votes
10answers
231932 views

real-time plotting in while loop with matplotlib

I am trying to plot some data from a camera in real time using OpenCV. However the real-time plotting (using matplotlib) doesn't seem to be working. I've isolated the problem into this simple example...
0
votes
1answers
798 views

How can i list has same id data with while loop in PHP?

I have a mysql table. column like that series_id, series_color, product_name I should list same series_id product like with group. I want like that list all same saries_id echo my screen like that...
484
votes
11answers
810428 views

Emulate a do-while loop in Python?

I need to emulate a do-while loop in a Python program. Unfortunately, the following straightforward code does not work: l = [ 1, 2, 3 ] i = l.__iter__() s = None while True : if s : print s t...
193
votes
7answers
93771 views

Else clause on Python while statement

I've noticed the following code is legal in Python. My question is why? Is there a specific reason? n = 5 while n != 0: print n n -= 1 else: print "what the..."
224
votes
34answers
81889 views

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 can't find ...
66
votes
5answers
81896 views

Read input in bash inside a while loop

I am having a bash script which is something like following, cat filename | while read line do read input; echo $input; done but this is clearly not giving me the right output as when I do ...

Previous Next