Python indentation deters newbies?
beliavsky@aol.com
beliavsky at 127.0.0.1
Mon Aug 16 19:25:37 EDT 2004
Jorge Godoy <godoy at ieee.org> wrote:
>Just an attempt and trying to keep it like your code.
Thanks. My code did not correctly illustrate breaking out of more than one
level of loop. How would the following code be translated to Python?
It is silly of course, but real-world situations where you want to exit a
nested loop are not that rare.
program xnest_loop
! illustrate breaking a nested loop
integer :: i,j,k,n
n = 4
ido: do i=1,n
jdo: do j=1,n
if (i+j > n) exit ido
do k=1,n
if (i+j-k < 0) exit jdo
print*,i,j,k
end do
end do jdo
end do ido
end program xnest_loop
output:
1 1 1
1 1 2
2 1 1
2 1 2
2 1 3
3 1 1
3 1 2
3 1 3
3 1 4
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
More information about the Python-list
mailing list