On Fri, Apr 19, 2013 at 1:35 PM, rusi <rustompm...@gmail.com> wrote: > If I have a loop: > > while i < len(a) and a[i] != x: > i++ > > I need to understand that at the end of the loop: > i >= len(a) or a[i] == x > and not > i >= len(a) and a[i] == x > nor > i == len(a) or a[i] == x # What if I forgot to initialize i?
Or your program has crashed out with an exception. >>> i,a,x=-10,"test","q" >>> while i < len(a) and a[i] != x: i+=1 Traceback (most recent call last): File "<pyshell#69>", line 1, in <module> while i < len(a) and a[i] != x: IndexError: string index out of range Or if that had been in C, it could have bombed with a segfault rather than a nice tidy exception. Definitely initialize i. But yeah, the basis of algebra is helpful, even critical, to understanding most expression evaluators. ChrisA -- http://mail.python.org/mailman/listinfo/python-list