Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43888
| References | <CAMjeLr_7A-NRtec=K_ZsjXA_oJHnD6+vpttz4Ma0vtDRbb+o2w@mail.gmail.com> <CAOvMSvXy=iJhUtMfncv-RE3HQw+7DJO-M1-TaeAFFhnDe9mpUA@mail.gmail.com> <BLU173-W31425FA225FA31B42E5B91CDCC0@phx.gbl> <mailman.804.1366325597.3114.python-list@python.org> <10511876-84bf-41f5-ad96-cf4ee5a6973e@di5g2000pbc.googlegroups.com> |
|---|---|
| Date | 2013-04-19 17:05 +1000 |
| Subject | Re: The type/object distinction and possible synthesis of OOP and imperative programming languages |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.815.1366355144.3114.python-list@python.org> (permalink) |
On Fri, Apr 19, 2013 at 1:35 PM, rusi <rustompmody@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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages Mark Janssen <dreamingforward@gmail.com> - 2013-04-18 15:53 -0700
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages rusi <rustompmody@gmail.com> - 2013-04-18 20:35 -0700
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages Mark Janssen <dreamingforward@gmail.com> - 2013-04-18 20:58 -0700
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages Chris Angelico <rosuav@gmail.com> - 2013-04-19 17:05 +1000
Re: The type/object distinction and possible synthesis of OOP and imperative programming languages Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-04-19 18:58 -0400
csiph-web