The structure of your code is a bit strange... why do you have the for
loop if you do not want to loop through it?
In your code i
will be assigned 1
then the repeat
loop will start until the condition is met and you break
out of it. Then i
will be assigned 2
and the repeat
loop will be reexecuted etc.
If you want the break
to go out of the for
loop that means you do not need the for
loop at all!
Anyways, the way to do it would be:
flag = 0
for(i in 1:n)
{
if (flag == 1)
break;
repeat
{
#code
if (condition)
{
flag <- 1
break
}
}
}
Although this would make no sense unless you have several different conditions to exit the repeat
loop, some of which do not set flag<-1