Loop label style question

151 views
Skip to first unread message

王富民awaw

unread,
Oct 3, 2023, 1:12:12 AM10/3/23
to golang-nuts
I wonder does anyone know the reason and history of why loop labels are styled as such:

* Labels are *unindented*.
  All Go constructs, such as fields in structs indent to the right.
  Why does loop labels unindented to the left?
* Labels start with capital letters.
  Since all other Go identifiers start with lower case, why is loop label an exception?

```
func foo() {
    ok := true
    // Why is the loop label unindented backwards to the left?
Loop:
    for {
        switch {
        case ok:
            // Why is the loop label capitalized?
            break Loop
        }
    }
}
```

Thanks in advance to those who are ancient enough to share the story behind loop labels.

Kurtis Rader

unread,
Oct 3, 2023, 1:34:50 AM10/3/23
to 王富民awaw, golang-nuts
I am writing a program that uses branch labels. It uses your example pattern to break out of a loop when a particular `select` situation occurs. Branch labels are not indented because they represent unusual locations for modifying the flow of control. This seems perfectly cromulent to me.

A branch label does not have to begin with a capital letter. Where did you get the idea it has to begin with a capital letter? Also, what you call a "loop" label is better characterized as a branch label.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c2bfd4c3-4a0e-4a53-b8a7-d700543c4ef0n%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
Reply all
Reply to author
Forward
0 new messages