> ?`break`
> ?`next`

> for(i in 1:13) {
    if(i < 13) next
    print("Hello!\n")
    }
[1] "Hello!\n"
> 


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile:                         +61 4 8819 4402
Home Phone:                     +61 7 3286 7700
mailto:[EMAIL PROTECTED]
http://www.cmis.csiro.au/bill.venables/ 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of tom soyer
Sent: Friday, 11 April 2008 12:26 PM
To: r-help@r-project.org
Subject: [R] for loop help

Hi,

I am trying to find a solution in R for the following C++ code that
allows
one to skip ahead in the loop:

for (x = 0; x <= 13; x++){
 x=12;
 cout << "Hello World";
}

Note that "Hello World" was printed only twice using this C++ loop. I
tried to do the same in R:

for(i in 1:13){
 i=12
 print("Hello World")
}
It doesn't work as I expected, i.e., this R loop prints "Hello World" 13
times.

Does anyone know how to do it in R?

Thanks,

-- 
Tom

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

______________________________________________
R-help@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.

Reply via email to