我想写一个 if 语句,它会继续重复一个问题,直到满足某个条件
像这样的东西:
fun<-function(){
x<-readline("what is x? ")
if(x>5)
{print("X must be less than 5")
**repeat lines 3 & 4**
}else{
print("Correct")}
}
很抱歉 **- 但我不确定如何正确编写该行。我要做的是每次输入大于 5 的数字时重复提示“x 是什么”,直到给出小于 5 的数字。理论上,函数看起来像这样
fun()
what is x? 6
X must be less than 5
what is x? 8
X must be less than 5
what is x? 3
Correct