Le lundi 24 octobre 2016 à 08:05 -0400, Isaiah Norton a écrit : > > > On Monday, October 24, 2016, Angel de Vicente <angel.vicente.garrido@ > gmail.com> wrote: > > Hi, > > > > I don't see it in the documentation, but I'm wondering if there is > > a way > > to have named nested loops, so that one can specify those names to > > break > > and continue, in order to have more control. > > > > In the following examples, continue always skips the remaining loop > > for > > j, while break terminates the j loop in the first example and > > terminates > > the single outer loop in the second (I guess it can be a bit > > confusing > > at first, but I can understand the design). > > > > ,---- > > | println("nested") > > | for i in 1:3 > > | for j in 1:6 > > | if 2 < j < 4 continue end > > | if j > 5 break end > > | @printf("i: %i j: %i \n",i,j) > > | end > > | end > > | > > | println("single outer loop") > > | for i in 1:3, j in 1:6 > > | if 2 < j < 4 continue end > > | if j > 5 break end > > | @printf("i: %i j: %i \n",i,j) > > | end > > `---- > > > > But I'm used to Fortran, where one can do things like this (CYCLE > > == > > continue ; EXIT == break), and you specify the loop that the > > instruction > > applies to. > > > > ,---- > > | INA: DO a = 1,1000 > > | INB: DO b=a+1,1000 > > | IF (a+b .GT. 1000) CYCLE INA > > | INC: DO c=b+1,1000 > > | IF (a+b+c .GT. 1000) CYCLE INB > > | IF (a+b+c .EQ. 1000 .AND. a**2 + b**2 .EQ. c**2) THEN > > | PRINT*, a*b*c > > | EXIT INA > > | END IF > > | END DO INC > > | END DO INB > > | END DO INA > > `---- > > > > > > Is it possible now (or in the near future) to have named nested > > loops in > > Julia? > > No, and I'm not aware of any plan to support this. But you can create > custom control flow with '@goto', so it could be probably be done > with a macro. A way to get out of multiple loops has actually been discussed, and the consensus appears to be that it's a good idea: https://github.com/JuliaLang/julia/issues/5334
Though it's not a high-priority feature since @goto works quite well. Regards > > > > Thanks, > > -- > > Ángel de Vicente > > http://www.iac.es/galeria/angelv/ > >