From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu From: Ralph Corderoy Message-ID: <18a0.3ed2038a.929e4@blake.inputplus.co.uk> References: <20030501160047.7231.qmail@g.bio.cse.psu.edu>, <20030507124006.D26796@cackle.proxima.alt.za> Subject: Re: [9fans] same functions everywhere Date: Tue, 27 May 2003 09:22:29 +0000 Topicbox-Message-UUID: b9303a4e-eacb-11e9-9e20-41e7f4b1d025 Hi Lucio, > I don't go along with that. Consider the conventional linear search > of an array: > > int a[100]; > int x, v; > > ... > > x = 0; > while (x < 100 && a[x] != v) { > ++x; > } > > (or whatever version you prefer). > > At the end, you always have to determine whether you found the desired > element or exceeded the array bounds. > ... > This particular problem has bugged me for decades :-) I go along with > Doug that exception handling can hide the extremely uninteresting code > involved in dealing with rare or "off band" conditions. Python solves this particular problem like this: a = [1, 2, 3] for x in range(len(a)): if a[x] == 42: print x break else: print -1 The for's else clause is only executed if a natural end to the loop is reached, i.e. you don't break out of it. Cheers, -- Ralph Corderoy. http://inputplus.co.uk/ralph/ http://troff.org/