I'm porting crack.c to crack.py.

I crack.c, I am able to do this:

for (int i = 0; i < sizeof(letters) && strcmp(hash, solve) != 0; i++)

In order to break the for() loop if I find the correct password before iterating through all the letters.

In crack.py, I want to do this:

for i in range(0, len(letters)) and hashish != solve:

In order to break the for() loop like I do in mario.c. Unfortunately, Python 3 returns the following error:

TypeError: 'bool' object is not iterable

What is a nice, simple method I can use to make a conditional for() loop, as described, that works with Python 3?


You could use while and somewhat emulate for, or do an if with a break inside your loop (which I would prefer).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .