<分区>
MainScreen() {
DisplayUI();
GetInput();
}
DisplayUI {
// prints press 1 for this 2 for that etc...
}
GetInput() {
// Gets input and calls the next approprite function according to that input e.g 1 for login etc...
// e.g
if (input == 1) {
Login();
}
.
.
.
if (input == x) {
somefunc();
}
// if the user enters an input that is not accounted for call this function
MainScreen();
}
Login() {
// do some stuff
MainScreen();
}
somefunc() {
// do some stuff
MainScreen();
}
main {
MainScreen();
}
使用上述方法是否有任何缺点(在每个函数实现的末尾都有 MainScreen();?)?
在此之上(使用 while 循环并从每个函数的末尾删除 MainScreen();)
哪个更好?无论哪种情况,我都想无限期地运行我的程序。我使用了上述方法并且我的程序运行完美,是否需要更改我的代码?
main {
while(true){
MainScreen(); //
}
}