Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8240383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:28:24+00:00 2026-06-07T20:28:24+00:00

In the below function, I would like to control the input so that if

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:28:26+00:00Added an answer on June 7, 2026 at 8:28 pm

    You can use a combination of switch and recursion

    ChooseTask <- function() {
        Load <- readline("Choose Task. 1, 2, or 3: ")
        switch(Load, 
               "1"={cat("1", "\n")},
               "2"={cat("2", "\n")},
               "3"={cat("3", "\n")},
                {
                    print.noquote("Must enter 1-3") 
                    ChooseTask()
                })
    }
    > ChooseTask()
    Choose Task. 1, 2, or 3: 2
    2 
    > ChooseTask()
    Choose Task. 1, 2, or 3: 5
    [1] Must enter 1-3
    Choose Task. 1, 2, or 3: 1
    1 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

AIM: I would like to set the below function to call every 5 seconds.
I would like the below function to be more flexible and accept multiple callbacks
I would like to animate an input control border where it changes colour twice
let say i have function like below function doSomethingNow(){ callSomethingInFutureNotExistNow(); } at the moment
I have a segmented control on the top of a tableView that I would
I have the following code to encrypt a value (listed below). Now I would
I would like to know that On Page refresh I would like to display
I would like some feedback regarding the IService class listed below. From what I
I have a control that has an attribute like this OnClientClick=checkfn( resultfn(boolval) ) checkfn
I'd like to call C# methods within a WebBrowser Control. Below is my code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.