What is Nostr?
mleku
npub1fjq…leku
2024-10-16 00:21:41

mleku on Nostr: one of the least well known features of #golang is the `for` keyword in Go, there is ...

one of the least well known features of #golang is the `for` keyword

in Go, there is one, it does all the things

it iterates arrays

it does forever loops

it can do standard C style `init;test;increment`

it recently acquired the ability to do "count to x" with `for range x`

and it does a while loop with `for <condition> {}`

no other language in a long time has actually reduced the complexity of this key element of all programming languages so elegantly

and it is within this structure that you can have labels (also in switches, but that's another story) and use `continue`, `break` and `goto` on these labels (switches also have `fallthrough` because they are a syntax sugar over if/else

a lot of languages tried to throw away goto, but it does have a very valid use in state machines, much cheaper than setting a state value and creating a switch on it

Go is the language for real programmers

it gets better every year, faster, simpler, more concise, more exact in its syntax, it is truly a gift from the heavens
Author Public Key
npub1fjqqy4a93z5zsjwsfxqhc2764kvykfdyttvldkkkdera8dr78vhsmmleku