Re: [R] Looping and break

2015-03-02 Thread Rolf Turner


On 03/03/15 16:08, Jeff Newmiller wrote:


Sigh. To be positive is to be wrong at the top of one's lungs. Next I
will be told R has a goto statement.


I am ***positive*** that it hasn't! :-)  Well, 99.999% confident. 
Although I guess it's not inconceivable that some misguided nerd might 
construct one.  In R all things are possible.  It'd be tough, but, in 
view of the fact that "statements" are not identified/identifiable in R 
so it would be hard to tell the code, uh, where to go.


cheers,

Rolf

--
Rolf Turner
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
Home phone: +64-9-480-4619

__
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.


Re: [R] Looping and break

2015-03-02 Thread Jeff Newmiller
Sigh. To be positive is to be wrong at the top of one's lungs. Next I will be 
told R has a goto statement.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On March 2, 2015 6:23:57 PM PST, Rolf Turner  wrote:
>On 03/03/15 15:04, Jeff Newmiller wrote:
>> Your example is decidedly not expressed in R, though it looks like
>> you tried. Can you provide the hand-computed result that you are
>> trying to obtain?
>>
>> Note that the reason you cannot find anything about next or break in
>> R is that they don't exist.
>
>Point of order, Mr. Chairman, but they ***do*** exist.  See e.g ?"next"
>
>(which actually takes you to the help for "Control Flow").
>
>> There are generally alternative ways to
>> accomplish the kinds of things you might want to accomplish without
>> them, and those alternatives often don't involve explicit loops at
>> all.
>
>Otherwise I concur with everything you say.
>
>cheers,
>
>Rolf

__
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.


Re: [R] Looping and break

2015-03-02 Thread Rolf Turner

On 03/03/15 15:04, Jeff Newmiller wrote:

Your example is decidedly not expressed in R, though it looks like
you tried. Can you provide the hand-computed result that you are
trying to obtain?

Note that the reason you cannot find anything about next or break in
R is that they don't exist.


Point of order, Mr. Chairman, but they ***do*** exist.  See e.g ?"next" 
(which actually takes you to the help for "Control Flow").



There are generally alternative ways to
accomplish the kinds of things you might want to accomplish without
them, and those alternatives often don't involve explicit loops at
all.


Otherwise I concur with everything you say.

cheers,

Rolf

--
Rolf Turner
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
Home phone: +64-9-480-4619

__
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.


Re: [R] Looping and break

2015-03-02 Thread Jeff Newmiller
Your example is decidedly not expressed in R, though it looks like you tried. 
Can you provide the hand-computed result that you are trying to obtain?

Note that the reason you cannot find anything about next or break in R is that 
they don't exist. There are generally alternative ways to accomplish the kinds 
of things you might want to accomplish without them, and those alternatives 
often don't involve explicit loops at all.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On March 2, 2015 4:11:21 PM PST, Scott Colwell  wrote:
>Hello,
>
>I apologies for bringing up next and break in loops given that there is
>so
>much on the net about it, but I've tried numerous examples found using
>Google and just can't seem to get this to work.
>
>This is a simple version of what I am doing with matrices but it shows
>the
>issue. I need to have the loop indexed as n to perform a calculation on
>the
>variable total. But if "total" is greater than 8, it goes to the next
>loop
>indexed "a".  For example, it does condition a = 1 for n = 1 to 50 but
>within n if total is greater than 8 it goes to the next condition of a
>which
>would be a = 2, and so on.
>
>for (a in 1:3){
>  
>  if (a == 1) { b <- c(1:5) }
>  if (a == 2) { b <- c(1:5) }
>  if (a == 3) { b <- c(1:5) }
>  
>  for (n in 1:50){
>  
> if (n > 15) next
>
> total <- 2*b
>  
> if (total > 8) next
>
>  }
>}
>
>Any help would be greatly appreciated.
>
>Thanks,
>
>Scott
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Looping-and-break-tp4704093.html
>Sent from the R help mailing list archive at Nabble.com.
>
>__
>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.

__
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.


[R] Looping and break

2015-03-02 Thread Scott Colwell
Hello,

I apologies for bringing up next and break in loops given that there is so
much on the net about it, but I've tried numerous examples found using
Google and just can't seem to get this to work.

This is a simple version of what I am doing with matrices but it shows the
issue. I need to have the loop indexed as n to perform a calculation on the
variable total. But if "total" is greater than 8, it goes to the next loop
indexed "a".  For example, it does condition a = 1 for n = 1 to 50 but
within n if total is greater than 8 it goes to the next condition of a which
would be a = 2, and so on.

for (a in 1:3){
  
  if (a == 1) { b <- c(1:5) }
  if (a == 2) { b <- c(1:5) }
  if (a == 3) { b <- c(1:5) }
  
  for (n in 1:50){
  
 if (n > 15) next

 total <- 2*b
  
 if (total > 8) next

  }
}

Any help would be greatly appreciated.

Thanks,

Scott



--
View this message in context: 
http://r.789695.n4.nabble.com/Looping-and-break-tp4704093.html
Sent from the R help mailing list archive at Nabble.com.

__
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.