A while loop is not designed to iterate through a list, while a for loop is. This is because a while loop is designed to continue going until certain conditions are met. Thus, you must do things manually. You could also do:Code:for line in lines: line_number = line_number + 1 if line[0] == " ": found_it = 0 cindex = 0 while cindex < len(linked_types) and found_it != 0: if linked_types[cindex] in line: found_it = 1 cindex=cindex+1
Still, the best way of all is:Code:for line in lines: line_number = line_number + 1 if line[0] == " ": found_it = 0 cindex = 0 lt2=linked_types[:] while len(lt2) and found_it != 0: types=lt2.pop() if types in line: found_it = 1 cindex=cindex+1
When iterating through a list, use a For loop. Its designed for it. Just use the break statement to break out of it when you so desire.Code:print "\nChecking the link types:" line_number for line in lines: if line[0] == " ": found_it = 0 for types in link_types: if types in line: found_it = 1 break if found_it == 0: print line




Reply With Quote