The break command can only break the innermost loop (the b loop in your
case). Rewrite the loop control logic. Here is one example
end.a <- FALSE;
for (a in 1:10) {
print(a);
for (b in 1:20) {
if (a > 5 && b > 5 ) {
end.a <- TRUE;
break; # Breaks the b loop
}
};
Hello,
Please could someone explain
break and next??
Is there a way to break a loop that is not the innermost loop??
for example:
#=
dim A = 1000 x 3
dim B = 2000 x 3
for (a in 1:1000){
for (b in 1:2000){
expr = intersect(A[a,1]:A[a,2],B[b,1]:B[b,2])
? `break`
On Tue, Jan 6, 2009 at 7:58 PM, kayj wrote:
> I was wondering if there is anything that breaks a loop in R
>
[[alternative HTML version deleted]]
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-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 wrote:
>
> Hi All,
>
> I was wondering if there
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 t
5 matches
Mail list logo