Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

while vs for

Name: Anonymous 2010-07-02 13:41

Whats the difference?

Name: Anonymous 2010-07-02 13:44

for(;;) is faster than while(1) because it doesn't have to check a condition on every pass. Other than that, they're basically equivalent.

Name: Anonymous 2010-07-02 13:52

You can write small loops inside the for(;;), and they generally work faster. while/break is better for abstracting state.
for(;;) does not check for condition  while(?) needs a condition to work.

Name: Anonymous 2010-07-02 13:57

>>2
e/10

Name: Anonymous 2010-07-02 14:01

>>2,3
>for(;;) is faster than while(1) because it doesn't have to check a condition on every pass
while(1) also does not have to check the condition, since it's constant. Read your SICP and Dragon book.

Name: Anonymous 2010-07-02 14:30

For is more flexible, but less readable.

Name: Anonymous 2010-07-02 14:35

They're both awful constructs that the imperative devil created to keep you stupid.

Use functional recursion instead.

Name: Anonymous 2010-07-02 14:36

Name: Anonymous 2010-07-02 14:51

>>2
for(;;)  is faster than while(1)  because it doesn't have to check a condition on every pass.
Looks like somebody's using a shitty compiler.

Name: Anonymous 2010-07-02 15:12

>>9
A compiler should do what you tell it to, not try to second-guess you and fix your mistakes for you.

Name: Anonymous 2010-07-02 15:23

>>10
0/10

Name: Anonymous 2010-07-02 18:29

>>7

functional recursion

WTF is that? Care to give an example?
.

Name: Anonymous 2010-07-02 18:36

>>12
2/10

Name: Anonymous 2010-07-02 19:33

>>11
Enjoy your Sepples mentality.

Name: Anonymous 2010-07-02 20:44

>>10
It's not second-guessing, it's called optimization. If you don't want your compiler to ``second-guess'' you, you should use assembly. Yes, I know that it's not called a ``compiler''.

Name: Anonymous 2010-07-02 21:02

>>15
Of course it's second-guessing. It's perfectly fine if it does it in -O1 or higher, but regular compilation should not fuck with your algorithm like that.

Name: Anonymous 2010-07-02 21:08

>>16
The difference between for (;;) and while (1) is not ``fucking with your algorithm''. They both do the exact same thing, and should compile to the same assembly.

Name: Anonymous 2010-07-02 21:52

It really is a trivial optimization. I bet GCC doesn't do it.

Name: Anonymous 2010-07-02 22:36

>>17
They don't do the same thing, and you're a moron for thinking they do. A proper compilation of while (1) will be slightly slower than a proper compilation of for (;;). If I want to write for (;;) I will, and the compiler should not get in my way if I write while (1) instead.

Name: Anonymous 2010-07-02 22:56

>>19

Implying that anyone would willingly write code that performs the same function as something else only with needless overhead

HIBT?

Name: Anonymous 2010-07-02 23:22

>>20
Polecat kebags.

Name: Anonymous 2010-07-02 23:49

I use while(1) strictly for its side-effects.

Name: Anonymous 2010-07-03 1:08

>>22
the standard doesn't guarantee any side effects for while(1).

Name: Anonymous 2010-07-03 1:14

>>23
The standard does guarantee that the condition for a while loop is checked on every pass, however. If your compiler produces the same assembly for while (1) and for(;;), it is broken.

Name: FrozenVoid 2010-07-03 1:22

If i need a real fast Infinite loop i use
label1:
loop();if(done){goto label2;}
goto label1;
label2://beats all those for/while loops and has zero overhead.

Name: Anonymous 2010-07-03 1:29

>>24
No, it isn't. The compiler is allowed to deduce that 1 has the same value on every pass and thus omit the check.

Name: Anonymous 2010-07-03 1:30

>>24
if the compiler can determine that checking the condition has no side effects and the condition cannot possibly change, it doesn't have to check it on every pass. if the condition is a compile-time constant, it doesn't have to check it at all. the standard only guarantees that it will be checked on every pass if checking the condition has side effects or the condition can change.

Name: Anonymous 2010-07-03 1:40

>>24
C99 5.1.2.3p3: In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce that its value is not used and that no needed side effects are produced (including any caused by calling a function or accessing a volatile object).

This idea is informally called the "as if" rule.

Name: Anonymous 2010-07-03 1:59

>>27-28
The important part here is if the condition has no needed side effects, which it clearly does, or the programmer would have used the more sensible for(;;) construct.

Name: Anonymous 2010-07-03 2:10

loeb
This thread is over.

Name: Anonymous 2010-07-03 2:25

It was a stupid thread to start with.

Name: Haxus the Harmful 2010-07-03 2:33

I use goto for all my flow control needs.

Name: Anonymous 2010-07-03 3:02

#There is no difference between for(;;) and while(1) on modern C compilers.
There, I even said it in red, making it an indisputable truth.

Name: Anonymous 2010-07-03 3:04

>>33
That would be besides the point even if it weren't imageboard assholery.

Name: Anonymous 2010-07-03 4:00

>>29
while(1) has no side effects.

Name: Anonymous 2010-07-03 4:30

while 5 characters
for 3 characters
3 < 5

Simple as that.

Name: Anonymous 2010-07-03 4:43

>>34
assholery
Back to where you came from, please.

Name: Anonymous 2010-07-03 6:15

You have to use the right terminator for each one. Remember: WHILE/WEND, but FOR/NEXT·

Name: Anonymous 2010-07-03 6:15

>>25
real fast infinite loop
loop()

you are a bad programmer and you should feel bad

Name: Anonymous 2010-07-03 6:36

pascal vs c

Whats the difference?

Name: Anonymous 2010-07-03 6:53

>>39
Meet FrozenVoid.

Name: Anonymous 2010-07-03 7:36

>>41
Hello, forgettable person whose name I have already forgotten because I am not a faggot.

Name: Anonymous 2010-07-03 7:42

>>42
Short-term memory is for GAYS

Name: Anonymous 2010-07-03 8:13

>>43
This thread is for gays. ANUS

Name: Anonymous 2010-07-03 16:19

>>42
Now that you mention it that was a decent approximation of FV-quality.

Name: Anonymous 2010-11-25 19:53

Name: Anonymous 2011-02-03 7:16


Don't change these.
Name: Email:
Entire Thread Thread List