[R] How to make this script ask again

David Winsemius dwinsemius at comcast.net
Sat Jan 1 20:27:16 CET 2011


On Jan 1, 2011, at 12:11 PM, ADias wrote:

>
> Hi,
>
> as an example I have made this script to give the user the answer if a
> number is odd or even:
>
> {
> cat("Please, enter a number (Zero ends)")
> n<-scan(n=1)
> if(n==0)break
> i<-("The number is odd")
> p<-("The number is even")
> if (n%%2==0)
> p else i
> }
>
> If you run this script it will only work once, I mean, after it  
> gives you
> the answer is won't ask for another number. You need to run the  
> script all
> over again. How could I change it in order to make it ask me for  
> another
> number without having to run the all script again?
>
> I have tried with the "repeat" but it doesn't work
>
> repeat {
> cat("Please, enter a number (Zero ends)")
> n<-scan(n=1)

Why do you set n=1 if you want more than one value?

> if(n==0)break
> i<-("The number is odd")
> p<-("The number is even")
> if (n%%2==0)
> p else i
> }

?Control

-- 
-- 
David
>
> thanks,
>
> Regards,
> ADias
> -- 
> View this message in context: http://r.789695.n4.nabble.com/How-to-make-this-script-ask-again-tp3170243p3170243.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list