這裏是我的代碼:C#如何在執行goto語句後返回上一步?
private void Mymethod()
{
if(animal == "Dog")
{
goto LabelMonsters;
}
//return here after goto LabelMonsters executes
if (animal == "Cat")
{
goto LabelMonsters;
}
//another return here after goto LabelMonsters executes
if (animal == "Bird")
{
goto LabelMonsters;
}
//Some long codes/execution here.
return;
LabelMonsters:
//Some Code
}
在我的例子,我有幾個if語句,第一次執行goto語句後,我必須回到我下的方法進行下一步。我嘗試繼續,但沒有工作。執行必須持續到最後。
作爲一個方面說明:你可以使用或改三'if'(''||)。 –
您可能想看看「方法」或「功能」。這些允許你執行一個子功能並返回。 – Luaan
學習構造代碼而不濫用goto?如果你需要退後一步,爲什麼不在退貨之前以標籤之後的代碼方式構造代碼? – user6144226