I am having a hard time with 'next'. I come from the "sloppy" school that 
learned BASIC with Goto.

Conceptually next seems pretty straightforward. I just can't get it to work 
correctly in my code. Here's a stripped down version:

WhichRunNow<-"Daily"
Cnums=c(0,1,"2b3")
Cpers=c("Daily","Daily","Weekly")

for (j in (1:length(Cnums))) {
     If (!identical(Cpers[j],WhichRunNow)){
           next
           }
     print(j)
}

So, this should print the number "3", which it does. It prints 3 because 
"WhichRunNow" is "Daily", and only for j=3 is Cpers[j] not identical to 
"Daily". But R seems very unhappy with how it gets there:

> WhichRunNow<-"Daily"
> Cnums=c(0,1,"2b3")
> Cpers=c("Daily","Daily","Weekly")
>
> for (j in (1:length(Cnums))) {
+ If (!identical(Cpers[j],WhichRunNow)){
Error: unexpected '{' in:
"for (j in (1:length(Cnums))) {
If (!identical(Cpers[j],WhichRunNow)){"
> next
Error: no loop for break/next, jumping to top level
> }
Error: unexpected '}' in "}"
> print(j)
[1] 3
> }
Error: unexpected '}' in "}"
>

Obviously something with my syntax, but I can't see what I'm doing wrong!


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to