在'for'循环Java中重新启动当前迭代 [英] Restart current iteration in 'for' loop java

查看:71
本文介绍了在'for'循环Java中重新启动当前迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个for循环,要求用户输入一个数字,然后用它进行10次操作

I have a for loop that asks the user to input a number and then does something with it 10 times

我要建立一个检查,如果用户输入了不被接受的输入,则循环应重新开始其当前迭代

I want a check built in that, if the user enters a non accepted input, the loop should restart its current iteration

例如,如果用户在第3轮中输入错误,则应重新启动第3轮.

For example if the user enters something wrong in round 3, round 3 should be restarted.

我该怎么做?Java中是否有类似REDO语句的内容?

How do i do that? is there something like a REDO statement in java?

推荐答案

类似的东西?

for(int i=0; i<10; i++){
   if(input wrong){
     i=i-1;
   }

}

这篇关于在'for'循环Java中重新启动当前迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆