How would you convert this 'goto' ?
This is a legacy code snippet that uses the magic goto, which I find it very difficult to understand and refactor.
doit:
foreach (var line in dict.Values)
{
var pts = new List<PointF>();
var rm = new Dictionary<string, LineData>();
doSomething(line, dict, pts, ref rm);
doSomethingWith(pts);
foreach (var item in rm.Values)
{
dict.Remove(item.ToString());
}
goto doit;
}
The goto doit jumps outside the loop. It isn't that bad because dict will eventually be cleared so that it does not cause endless loop.
How would you rewrite this? See answer here: https://helloacm.com/coding-review-how-would-you-convert-this-goto/
我写程序从不用goto,这玩意就是一个炸弹,没有处理好随时会爆炸.
是的,用GOTO的地方几乎都可以被重写。
This post has received a 11.05 % upvote from @boomerang thanks to: @justyy
@boomerang distributes 100% of the SBD and up to 80% of the Curation Rewards to STEEM POWER Delegators. If you want to bid for votes or want to delegate SP please read the @boomerang whitepaper.