3 ms·
But it's not a 1-by-1 mapping. The FOR-loops of FORTRAN, ALGOL, and Pascal have 1-to-1 mapping to the sigma notation because the increment part is either a) omi
by Joker_vD 3y ago
But it's not a 1-by-1 mapping. The FOR-loops of FORTRAN, ALGOL, and Pascal have 1-to-1 mapping to the sigma notation because the increment part is either a) omitted entirely and forced to be +1; b) allowed to be some other integer constant, but definitely not an integer expression.
FOR i := 1 TO 10 DO ...
FOR i := 20 STEP -2 UNTIL 0 DO ...
for (i=0, j=10; s[i]; t[j--] = s[i++]); // huh?
- lelanthran 3y ago> for (i=0, j=10; s[i]; t[j--] = s[i++]); // huh? If you need to mischaracterise and mislead with your examples, you probably don't have a a good argument. The equivalent C code to your other examples are: for (i = 1; i <= 10; i++) { ... } for (i = 20; i >= 0; i -= 2) { ... } Your argument makes less sense when you write the counter-example out correctly, see?
- Joker_vD 3y agoMy argument is that there is no 1:1 mapping: for instance, "for (i=0, j=10; s[i]; t[j--] = s[i++])" has no direct correspondence with sigma notation. Does it? I don't believe so. This code also has no direct correspondence to Pascal's FOR or FORTRAN's DO, or ALGOL's FOR-STEP loops. Hence, C's for loop has no 1:1 mapping to sigma notation. Of course, I can be mistaken and either there actually is a 1:1 mapping, or you meant by "1:1 mapping" something quite different from what I mean.
- lelanthran 3y ago> My argument is that there is no 1:1 mapping: for instance, "for (i=0, j=10; s[i]; t[j--] = s[i++])" has no direct correspondence with sigma notation. And? I didn't claim that all the multi-expression, body-in-the-conditional possibilities are a 1:1 mapping with sigma notation, did I? Why do you think this is more representative of for loops in C than simpler examples I gave? > or you meant by "1:1 mapping" something quite different from what I mean. Well, yes. I meant that the 1:1 mapping is from sigma notation to C, not the other way around, because sigma notation was not invented after the C language. Maybe I shouldn't have said 1:1 mapping; it's much clearer to say "The `for` loop in C is just a way to write sigma notation in programming languages".