My advice is: Don't loop with while! (Not in arcpy, and not in previous versions of arcgis either). The ArcGIS sample code is written by someone not knowing python.arcpy version:
listmdb = arcpy.ListWorkspaces('*', 'FileGDB')
for mdb in listmdb:
print mdb
# same logic as above
# change inner loops to for loops too
# don't call next, since it's done behind the scene with the for loop
ArcGIS 9.2 version:
listmdb = gp.ListWorkspaces('*', 'FileGDB')
for mdb in iter(listmdb.next, None): # Note: no function parantheses following next
print mdb
# same logic as above
# change inner loops to for loops too
# don't call next, since it's done behind the scene with the for loop