breasking out of a while loop (in an if statement)

Lee Reilly CS1997 lreilly at cs.strath.ac.uk
Tue Feb 13 21:36:40 CET 2001


Hi, I wonder if anyone could be kind enough to point out what I am doing
wrong here (please see code below).

The problem arises in the last 5 lines of code. 'result' is a database
query result (type string). If it's empty then it has size==2 and if not
then it's >=3. If it is empty then I have placed a return value after
it. However, if it is not then I would like it to go back around the
while loop. The code *looks* okay...

-=---=-=--=-==-=-=-=-==
while (j!=0):
    if (radiobutton=='comma'):
        tempString = string.split(text[i-1], ",")
    else:
        tempString = string.split(text[i-1], "\t")

    matric = string.rstrip(string.lstrip(tempString[0]))
    SQL = "select * from STUDENTS where matric= '" + matric + "'"
    result=db_conn.query(SQL)
    result = len(result)
    if (result>=3):
       return "Student with matric value " + matric + " already exists
in the database"
       # break
    else:
        j=j-1
-=---=-=--=-==-=-=-=-==

=> Error Type: IndexError
=> Error Value: list index out of range

I'm using Python with Zope BTW.

Can anyone see my problem? Any help would be greatly appreciated ;-)

- Best regards,
Lee Reilly



More information about the Python-list mailing list