Usando exit y cycle en do anidados Fortran

Es interesante ver que cycle y exit pueden ser usados para saltar entre do anidados

PROGRAM test_cycle_2
INTEGER :: i, j, product
outer: DO i = 1, 3
inner: DO j = 1, 3
IF ( j == 2) CYCLE outer
product = i * j
WRITE (*,*) i, ' * ', j, ' = ', product
END DO inner
END DO outer
END PROGRAM test_cycle_2


que produce

           1  *            1  =            1
           2  *            1  =            2
           3  *            1  =            3
 

Comentarios

  1. This article provides a clear explanation of how to use exit and cycle in nested loops within Fortran, making code more efficient and readable. If you're a gamer too, subtitleedit is an excellent tool to keep your game library organized while you dive into Fortran coding!"

    ResponderEliminar

Publicar un comentario

Entradas populares de este blog

ERROR: Grib2 file or date problem, stopping in edition_num. Can't ungrib.exe SOLVED

ARCGIS: Cálculo de pendiente entre puntos en el espacio xyz

WRF open_aux_u : error opening auxinput5_d02_2013-12-31_00:00:00 for reading. 100