On 07.12.2024 14:04, Bart wrote:
On 07/12/2024 11:34, Janis Papanagnou wrote:
On 06.12.2024 02:20, Bart wrote:
I used to be puzzled by this too: 'while' can both start a while
statement, and it can delimit a do-while statement. How is that
possible?
>
A keyword (like 'while') is just a lexical token that can be used in
different syntactical contexts.
Is it common to both start and end a statememt with the same keyword?
It's at least nothing that surprises (or even annoys) me.
(Even with different semantics, if a
language designer thinks this is a good idea for his case.)
>
You may be less confused with using Pascal;
Now you are demonstrating my point about being treated like a beginner.
And it is exasperating.
If so then that was unintentionally. - My apologies! - It was merely
meant as an example of a language that has chosen different keywords
with complementary conditions, thus somewhat covering both options.
Personally I'd have preferred to have all four variants (see below)
available since often I needed a 'repeat' ... 'while' ... logic in
my programs. (Which incidentally is what "C" supports.)
So are you now saying that if "C" had 'while (...) ...' and also
'do ... until (...)' that would not have solved your "problem" here?
I thought it would have since you complained about a keyword used in
two control constructs.
This is a point of language design. C's approach works - just.
Just fine, I'd say.
But it relies on some subtlety.
You seem to see ghosts. There's no subtlety; all is clearly defined,
and it's a sensible feature, and consistently implemented.
'while (cond)' both starts a statement, and can
end a statement:
do while(cond) do ; while (cond);
What is this (IMO syntactical wrong "C" code) supposed to do or to
explain?
Did you maybe mean do while(cond) ; while (cond); which should
of course be sensibly formatted to not confuse folks, as in
do
while (cond)
;
while (cond);
so that it's control-flow can easily be understood. If that is still
confusing you could add braces.
The second 'while' here starts a nested while-loop inside a do-while
loop. Not confusing?
Your (wrong) second 'do' was indeed confusing! - Why did you provide
a wrong sample to confirm your wrong ideas? - Or is it just your well
known habit to try to confuse other folks as well my making up stupid
things?
It is to me! I couldn't finish my example as I got
lost (but as it happens, this is valid code, partly by luck).
It produces errors if I compile your (wrong) code. - What do you thus
mean by it being "valid code"?
Of course, if you put aside all other matters and concentrate on the
minutiae of the syntax details, then it is all 'obvious'. I think it
needs to be a lot more obvious.
Most here (and me too) already acknowledged that "C" is not obvious
to you. (No there's no need to repeat and document that constantly.)
while positive-case do ...
until negative-case do ...
do ... while positive-case
do ... until negative-case
(depending on language with this of similar syntax).
>
There's nothing wrong using the same keyword for the same type of
condition, rather it's good to have it defined that way.
The problem here is exactly the same: how do you tell whether the
'while' in 'do ... while' is ending this 'do'-loop, or starting a nested
while-loop?
That's called "[unambiguous] _Syntax_". - I don't know about "your
languages", but all serious languages I know of have such syntaxes.
And the programmers (of the respective various languages) I met had
no problems understanding such syntaxes.
(If you have a problem with perception it might be of help to use
a pretty printer on "non-obvious" code. If it's rather a matter of
understanding the concept then making yourself familiar with syntax
is more appropriate; certainly better than posting your confusion
repeatedly and spreading FUD [for potential newbies].)
You don't think there is an element of ambiguity here?
There isn't any.
Let's take my example again:
By repeating that it doesn't fix _your_ problem.
do while(cond) do ; while (cond);
And make a small tweak:
do ; while(cond) do ; while (cond);
It still compiles, it is still valid code.
None of these two examples compile in my environment, and none looks
like "valid code" to me. - There's a spurious 'do' as already said,
or a missing ';', depending on the control-logic you intended...
do while (cond) ; while (cond);
do ; while (cond); do ; while (cond);
Did you check that code maybe only (in "your language") with "your
compiler"?
But now it does something
utterly different. (One is two nested loops, the other is two
consecutive loops - I think!)
OK, I get now that people just aren't that bothered about such matters.
(You seem to be living in some parallel fantasy world.)
Obviously they aren't language designers.
Huh?
Janis