It is quite a late answer for you but, Deluge does not natively support while loops. that is why it is expecting you to close the line of code but instead it gets a curly brace.
see [this link][1] to elaborate on how you could create a for each loop to act like a while loop.