Last active
August 29, 2015 14:23
-
-
Save uekkie/b47a9219abe1f499bdbc to your computer and use it in GitHub Desktop.
gotoをdo while (0)で置換する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// チェックをすべてパスした時に、特定の処理をおこなう。 | |
// チェックが失敗したあとも、特定の処理をおこなう。 | |
bool gotoHeaven() | |
{ | |
if(!check1()) | |
{ | |
// do something... | |
goto HELL; | |
} | |
if(!check2()) | |
{ | |
// do something... | |
goto HELL; | |
} | |
initPrayCount(); // 祈りカウンタを初期化する | |
return true; | |
HELL: | |
incrementPrayCount(); // 祈りカウンタを加算する | |
return false; | |
} | |
bool dowhileHeaven() | |
{ | |
do { | |
if(!check1()) | |
{ | |
// do something... | |
break; | |
} | |
if(!check2()) | |
{ | |
// do something... | |
break; | |
} | |
initPrayCount(); // 祈りカウンタを初期化する | |
return true; | |
} while(0); | |
incrementPrayCount(); // 祈りカウンタを加算する | |
return false; | |
} | |
// | |
// むしゃくしゃしてやった。gotoを消せればなんでもよかった。今は反省している。 | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gotoはすべて駆逐する!