Menu Close

Cycle & Exit Statement | Fortran

program cycle_exit
implicit none
INTEGER::n,i,s,e


PRINT *, '============================================'
PRINT *, 'PROGRAM TO UNDERSTAND CYCLE & EXIT [ BY - BOTTOMSCIENCE.COM ]'
PRINT *, '============================================'

print *, 'Enter the total number you want to print'
read(*,*) n

print *, 'Enter the number which you want to skip to print'
read(*,*) s

print *, 'Enter the number which you want to stop the printing'
read(*,*) e

do i=1,n
if(i==e) exit
if(i==s) cycle
print *,i
end do

end program

OUTPUT

============================================
PROGRAM TO UNDERSTAND CYCLE & EXIT [ BY – BOTTOMSCIENCE.COM ]============================================
Enter the total number you want to print
5
Enter the number which you want to skip to print
3
Enter the number which you want to stop the printing
5
1
2
4

More Related Stuff