[R] How to make this script ask again

ADias diasandre at gmail.com
Sat Jan 1 18:11:51 CET 2011


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

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.



More information about the R-help mailing list