{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/1597","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/1597/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/1597/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/1597/events","html_url":"https://github.com/dotnet/csharplang/issues/1597","id":328725098,"node_id":"MDU6SXNzdWUzMjg3MjUwOTg=","number":1597,"title":"[Proposal] Labeled loops like in Java","user":{"login":"AustinBryan","id":16201886,"node_id":"MDQ6VXNlcjE2MjAxODg2","avatar_url":"https://avatars1.githubusercontent.com/u/16201886?v=4","gravatar_id":"","url":"https://api.github.com/users/AustinBryan","html_url":"https://github.com/AustinBryan","followers_url":"https://api.github.com/users/AustinBryan/followers","following_url":"https://api.github.com/users/AustinBryan/following{/other_user}","gists_url":"https://api.github.com/users/AustinBryan/gists{/gist_id}","starred_url":"https://api.github.com/users/AustinBryan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AustinBryan/subscriptions","organizations_url":"https://api.github.com/users/AustinBryan/orgs","repos_url":"https://api.github.com/users/AustinBryan/repos","events_url":"https://api.github.com/users/AustinBryan/events{/privacy}","received_events_url":"https://api.github.com/users/AustinBryan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":46,"created_at":"2018-06-02T08:12:51Z","updated_at":"2018-06-15T13:12:48Z","closed_at":null,"author_association":"NONE","body":"Currently the cleanest way to break out of a nested loop is this:\r\n\r\n```csharp\r\nfor (int i = 0; i < 5; i++)\r\n    for (int j = 0; j < 3; j++)\r\n        if (i * j == 10) \r\n            goto outer;\r\n\r\nouter: {}\r\n```\r\n\r\nIf all we wanted to do was break out of the loops, we have to do `outer: {}`, which is sort've clunky. What we could do instead is use labeled loops like Java, so we can do this:\r\n\r\n```Java\r\nouter: for (int i = 0; i < 5; i++)\r\n    inner: for (int j = 0; j < 3; j++)\r\n        if (i * j == 10) \r\n            break outer;\r\n```\r\n\r\nAnd instead of:\r\n\r\n```csharp\r\nint j = 0;\r\n\r\nfor (int i = 0; i < 5; i++)\r\n    inner: for (; j < 3; j++)\r\n        if (i * j == 10) \r\n            goto inner;\r\n```\r\nWe can just do:\r\n\r\n```Java\r\nfor (int i = 0; i < 5; i++)\r\n    inner: for (j = 0; j < 3; j++)\r\n        if (i * j == 10) \r\n            continue inner;\r\n```\r\nThe alternative is cleaner, more intuitive, and simpler. \r\n\r\nI saw another post where they suggest doing `break 1;` to break the first loop, but that doesn't refactor well if the number of loops changes, you have to carefully make sure the numbers are correct. "},"comment":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/comments/397615703","html_url":"https://github.com/dotnet/csharplang/issues/1597#issuecomment-397615703","issue_url":"https://api.github.com/repos/dotnet/csharplang/issues/1597","id":397615703,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NzYxNTcwMw==","user":{"login":"Mafii","id":10061519,"node_id":"MDQ6VXNlcjEwMDYxNTE5","avatar_url":"https://avatars0.githubusercontent.com/u/10061519?v=4","gravatar_id":"","url":"https://api.github.com/users/Mafii","html_url":"https://github.com/Mafii","followers_url":"https://api.github.com/users/Mafii/followers","following_url":"https://api.github.com/users/Mafii/following{/other_user}","gists_url":"https://api.github.com/users/Mafii/gists{/gist_id}","starred_url":"https://api.github.com/users/Mafii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mafii/subscriptions","organizations_url":"https://api.github.com/users/Mafii/orgs","repos_url":"https://api.github.com/users/Mafii/repos","events_url":"https://api.github.com/users/Mafii/events{/privacy}","received_events_url":"https://api.github.com/users/Mafii/received_events","type":"User","site_admin":false},"created_at":"2018-06-15T13:12:48Z","updated_at":"2018-06-15T13:12:48Z","author_association":"NONE","body":"@jez9999 \r\n\r\n> And returning tuples from methods is just a case of returning the appropriate Tuple class and consuming it from the other end, yet C# just introduced a shorthand for that.\r\n\r\nYes, but it's an approach the LDM wants to support, and advocate. It's a new approach, and having named returns and everything supports that approach. if it's easier to use, it's going to be used more often. No one is going to _not_ using loops just because we _don't have labeled loops_. For the rest, I can't say it better than Cyrus. It's not about how big the change is, but about what it really adds to the language. And what it propagates for the developers."}}
{"actor":{"display_login":"Mafii"}}