C, C++, Java suxx for a while ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Your computer science teacher gave a course about flow control structures and you got a headache grasping the difference between "repeat-until" and "while-endwhile"? In such case DON'T read this text or your brain will be utterly damaged. Let's consider the following programs: /******** for.c *********/ /******* while.c ********/ #include #include int main(){ int main(){ char c; char c; for(c=1;c<10;c++){ c=1; printf("%d",c); while(c<10){ } printf("%d",c); } c++; } } As you can see, they use different flow control structures. BASIC coders will have problem with the for() statement, which is very different from the "FOR c=1 TO 9 STEP 1" they are used to. And that's normal because: !!!! IN C, THE FOR STATEMENT IS IN FACT A WHILE !!!! To prove this, i compiled both programs with different compilers, and they gave EXACTLY THE SAME EXECUTABLE (Norcroft C v4.00 and GCC 2.95.2 pre3a on RiscOS) or the same assembly source, except for some debug informations and useless labels (Turbo C 2.01 on DOS, see Appendix). source \/ +------\/------+ | preprocessor <<< other source files In usual C compilers, the +------\/------+ compilation proceeds by \/ successive steps, which are +------\/------+ naively summarised on the | compiler | right (they depend on the +------\/------+ compiler, and there are \/ a lot more invisibles steps). +------\/------+ | linker <<< other objects file +------\/------+ \/ executable During the processing step, all the "for(A;B;C) {...}" statements are converted in "A;while(B) {... C}" statements. Thus the compiler only has to cope with the while structure. The problem is that a for structure can generally be easily optimised in assembly language with a decrement+branch (except when the step or bounds are variables), and i'm not that sure the compiler will optimise it correctly. So believe it, C, C++, Java suxx... ;p BASIC rulez! Alain Brobecker ---- Appendix: for.asm, while.asm & differences ---- begin 644 8086asm.zip M4$L#!!0 @ ( +A1KB@9\K]V5P$ "$# ' !@ 1D]2+D%334%#% !!4D,Pa M2?___Q#^@;XS )52RT[#,! \[WY%;KD8*7T)*2<#K3@6T2(A(13%a MCML&Y6'9#@U_C^VX55N0H*>U=V=GQKO.UHO7-6BQK45C@'T9$K%4*N=5<+X#K-' -B!5RZ$1N4*0G=X!DPAU^VDCT?:H.P9:DG%(>A:CHCB-:B!,(/7;.K$# QJ\670Y_ 90a M2P,$% " @ MU*N*%4*WL>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