fix dangling else example #18

Closed
zhuscat wants to merge 1 commit from patch-1 into master
zhuscat commented 2024-01-31 18:00:55 +01:00 (Migrated from github.com)
No description provided.
marijnh commented 2024-01-31 18:07:00 +01:00 (Migrated from github.com)

That breaks the example—with that change, the association of the else is no longer ambiguous.

That breaks the example—with that change, the association of the `else` is no longer ambiguous.
zhuscat commented 2024-02-02 04:49:21 +01:00 (Migrated from github.com)

Thank you for your reply, but I'm still a little confused.

According to Dangling else, if we don't specify the precedence of else, the following code:

if (a)
if (b) {}
else {}

can be interpreted as:

if (a) {
  if (b) {}
} else {}

or

if (a) {
  if (b) {}
  else {}
}

But why is the following code ambiguous?

if (a) {}
if (b) {}
else {}
Thank you for your reply, but I'm still a little confused. According to [Dangling else](https://en.wikipedia.org/wiki/Dangling_else), if we don't specify the precedence of else, the following code: ```js if (a) if (b) {} else {} ``` can be interpreted as: ```js if (a) { if (b) {} } else {} ``` or ```js if (a) { if (b) {} else {} } ``` But why is the following code ambiguous? ```js if (a) {} if (b) {} else {} ```
marijnh commented 2024-02-02 09:50:23 +01:00 (Migrated from github.com)

But why is the following code ambiguous?

It's not. And as such it's no use for illustrating this potential ambiguity.

> But why is the following code ambiguous? It's not. And as such it's no use for illustrating this potential ambiguity.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/website!18
No description provided.