Skip to content

breaking a loop in R

3 messages · kayj, jim holtman, Stavros Macrakis

#
Hi All,

I was wondering if there is anything that breaks a loop in R. For example, 


For (k in 1:100)
For ( i in 1:10){

If ( condition ){
Break the inner loop 
} 

}
}

In the above case, if the program runs the if statement, then I want the
inner loop for (i in 1:10) to stop looping and skip the rest of the program.

Thanks for your help
#
something like this should do it:

breakFlag <- FALSE
For (k in 1:100)
    For ( i in 1:10){

        If ( condition ){
            breakFlag <- TRUE
            break
        }

    }
    if (breakFlag) break
}
On Tue, Jan 6, 2009 at 7:58 PM, kayj <kjaja27 at yahoo.com> wrote: