In the below function, I would like to control the input so that if any value but the first three choices (any value that does not equal 1-3) are entered the function will loop back to the original question.
T<-function(){
Load<-readline("
Choose Task
1 Task 1
2 Task 2
3 Task 3 ")
for(i in 1:10){
if(Load=="")
{print.noquote("No Value Entered"); Load<-readline("
Choose Task
1 Task 1
2 Task 2
3 Task 3 ")
}else
if(Load==1)
{source("/Users/JD/Desktop/R1.R")}
else
if(Load==2)
{source("/Users/JD/Desktop/R2.R",print.eval=TRUE)}
else
if(Load==3)
{source("/Users/JD/Desktop/R3.R",print.eval=TRUE)}
else
{print.noquote("Must enter 1-3"); ** loop back to "Choose Task"**}
}}
So where I have the ** would be a line looping back to the second line of the code. I’ve already controlled for a “blank” response, but I would like to do something similar for anything not equaling 1-3. If looping back is not allowed, perhaps there may be a different way to get the same effect.
You can use a combination of
switchand recursion