Liste des Groupes | Revenir à cl c |
(While there's some "C" stuff in here it contains a lot of non-"C"
samples for comparison. So [OT]-sensible folks may want to skip this
post.)
I'm not saying there's anything wrong with it. The point was that an A to B loop existed in the 1950s; C came out in the 1970s!Fortran's loops looked like this:Okay, I see what you want; just two values (from, to).
>
do 100 i = a, b
s1
s2
...
100 continue
This Fortran stuff looks really sick (for my taste)! - The "do 100"
sounds like iterating 100 times, line numbers, 'continue' keyword,
and a list a,b meaning iteration over a range. - Can it be worse?
(Later Fortran versions allow a slightly better syntax, but it's
basically the same anachronistic crude syntax.)
In _minimalistic_ languages I'd prefer, for example, a style like
in Pascal (or in similar languages)
for i := a to b do
statement_block;
No, it's just 'i' in this example.* Fortran has an official loop index variable 'i'.You are saying that you could not use 'j' ?
which of course would be written with a 'while'That would be a poor use of 'while'. And bizarre, to use 'while' for iteration, but 'for' for loops that are best written as while!
int i = a;
while (i <= b) f(i++)
The "C" syntax has actually a flexibility that is very valuable.The flexibility is the problem, because you have to specify the loop in such excruciating detail. It is easy to make a mistake which results in still legal code. And you now have to analyse each loop to see what kind of loop it is:
(Even though I dislike its syntax, but that is a minor point inThis is the kind of error I was making all the time (writing the first line, copying it, but forgetting to convert all the variables):
this context).
>They don't need to be identical, because you can write many more
* C needs you to provide the exact comparison op
>
* C needs you to write the index 'i' three times (with no compiler check
that they're all identical!)
types of loops than simple counted loops. - This is actually an
advantage;
it allows a lot more sensible loop code patterns than>It sounds like you're being insulting again just to keep your hand in. Why is it some people just cannot resist getting personal?
those other primitive loops! - I'm astonished that your code
pattern repertoire is so limited. (Or that you are arguing again
just to contribute anything, however stupid that is.)
You need to tell the computer how to count? OK!>Of course; another advantage! (And this is common in many
* C needs you to specify how to increment the loop index
programming languages, older and newer ones.)
I don't understand; what exactly is the problem here that you see as nonsensical?* Fortran allows an arbitrary number of statements in the loop body.Jesus! - At times I see you as a sensible communication partner,
C allows only one; multiple statements require a compound statement.
but in this sub-thread I've no hope. - I'll finish this post and
stop responding to such stupid posts of yours...
Yes I have issues with *constantly* switch from lower case all-caps. It is tedious, error prone and the result is ugly code.[...](Huh? You have issues with keywords in caps?
>
Algol68 also ignores white space, at least within identifiers. That
would have caused clashes with reserved words, so that 'stropping' had
to be employed, resulting in ugly and fiddly-to-type source code.
There were various stropping methods used in the past, some(Note: Algol68 comments need a trailing # too.)
better some worse. The Genie compiler-interpreter uses all caps
and it looks great; makes the keywords stand out and makes the
code structure very clear and perfectly legible! (YMMV.)
And you have a powerful, yet minimalistic syntax; you "pay"
only for what you need and can express anything. Examples...
# infinite loop
DO s1; s2 OD
# loops n times (no variable necessary)
TO n DO s1; s2 OD
# infinite loop with counted index available
FOR i DO s1; s2(i) OD
# loop n times with variable value available
FOR i TO n DO s1; s2(i) OD
... and so on until...
# full arithmetic loop (start, increment, end)
FOR i FROM k BY 3 TO m DO s1; s2(i) OD
# full arithmetic loop with condition
FOR i FROM k BY 3 TO m WHILE cond(i) DO s1; s2 OD
# only condition (no arithmetic)
WHILE cond DO s1; s2 OD
# only condition (with preparing statements)
WHILE s1; s2; cond DO s1; s2 OD
What you can see here are a couple of advantages withAs I said, I have the same features, but it is multiple constructs. So having 'one construct' is just a gimmick.
this sort of loop;
* one formal construct (not many variants) to express
all the common loop controls
* better readability (because of stropping!); an easyThat's rubbish too. I can also write:
differentiation of syntax structure and user defined
entities (variables, conditions, functions, ...)
* all loop-parts (but DO and OD) optional; no typingI have sensible defaults too! I also don't have annoying rules about semicolons, or problems with empty bodies:
overhead, clear constructs, sensible defaults for
omitted parts
The Simula loop, while not as rich as Algol 68's, hasWhat is it demonstrating? Since it seems to be merely this:
also some distinct specifics; just a short example
FOR z := 2, 3, 5, 7, 11, 13, 17, 19,
21 STEP 2 UNTIL 99,
z+1 WHILE p(z) DO ...
And you think Fortran's loop is a good paragon? *sigh*It seems we could have kept this short.
Les messages affichés proviennent d'usenet.