golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.73k stars 17.63k forks source link

proposal: add `do...for` loop #70064

Closed lorypelli closed 3 hours ago

lorypelli commented 3 hours ago

Go Programming Experience

Intermediate

Other Languages Experience

JS, TS, Python, C, Java, Kotlin

Related Idea

Has this idea, or one like it, been proposed before?

No, it would be good to make a loop executed at least one time without duplicating code...

Does this affect error handling?

No

Is this about generics?

No

Proposal

sintax like this maybe: i := 0 do { i++ println(i) } for (i < 5)

Language Spec Changes

No response

Informal Change

No response

Is this change backward compatible?

There is an entire new keyword and loop body is in a different place, I don't think so...

Orthogonality: How does this change interact or overlap with existing features?

No response

Would this change make Go easier or harder to learn, and why?

No response

Cost Description

No response

Changes to Go ToolChain

No response

Performance Costs

No response

Prototype

No response

gabyhelp commented 3 hours ago

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

seankhliao commented 3 hours ago

Duplicate of #55868

lorypelli commented 2 hours ago

Duplicate of #55868

that issue was closed and I don't like using break keyword

lorypelli commented 2 hours ago

and that would also be an infinite loop which is not that cool

seankhliao commented 2 hours ago

Duplicate of #34896

seankhliao commented 2 hours ago

in either case adding more syntax sugar isn't really the solution