Nested while-s

Harald Hanche-Olsen hanche at math.ntnu.no
Sat Jan 15 00:35:48 EST 2000


+ josht at iname.com (Josh Tompkins):

| Is it not possible to nest while's?

It sure is.

| Consider this code:
| 
| def listOfRadius(radius, xpos, ypos):
| 	list = []
| 	currentX = (xpos - radius)
| 	currentY = (ypos - radius)
| 	while currentX <= (xpos + radius):
| 	    while currentY <= (ypos + radius):
| 		    str1 = `currentX` + " , " + `currentY`
| 		    list.append(str1)
| 		    currentY = currentY + 1
| 	    currentX = currentX + 1
| 	return list
| 
| It will list only the values from the nested while.

Move the initialization of currentY into the top of the outer while
loop.

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- "There arises from a bad and unapt formation of words
   a wonderful obstruction to the mind."  - Francis Bacon



More information about the Python-list mailing list