Objective-C:switch 语句完成后如何返回到应用程序的开头
例如,
在您的程序中:
NSLog(@"Where are you going?");
NSLog(@" 1 = Location1, 2 = Location2");
printf("Make a selection:");
scanf("%i, &value);
switch (value) {
case 1:
NSLog(@"You are going to Location 1.")
break;
case 2:
NSLog(@"You are going to Location 2.");
break;
default:
NSLog(@"That is not a valid location");
break;
}
通常在输入整数后,您的程序将返回 0 并且应用程序结束。你如何让它“循环”回到原来的 printf 来做出新的选择。或者更好的是,一个新的 printf IE 'printf("你还想去哪里?:");'?
For example,
In your program you have:
NSLog(@"Where are you going?");
NSLog(@" 1 = Location1, 2 = Location2");
printf("Make a selection:");
scanf("%i, &value);
switch (value) {
case 1:
NSLog(@"You are going to Location 1.")
break;
case 2:
NSLog(@"You are going to Location 2.");
break;
default:
NSLog(@"That is not a valid location");
break;
}
Normally after you input your integer your program will return 0 and the application ends. How do you go about having it "loop" back to the original printf to make a new selection. Or even better, a new printf IE 'printf("Where else would you like to go?:");'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不将其保留为单独的方法,并在需要循环时从自身调用它。只需考虑以下代码,
Why don't you keep it as a separate method and call it from itself when you want to loop. Just consider the following code,