Re: probable mistake in IDL manual [message #10456 is a reply to message #10382] |
Tue, 02 December 1997 00:00  |
David Foster
Messages: 341 Registered: January 1996
|
Senior Member |
|
|
Saeid Zoonematkermani wrote:
>
> ------
> pro Animals
> animals = 'dog cat duck rabbit dog cat dog'
> i = 0
> cnt = 0
> while (i ne -1) do begin
> i = strpos(animals,'dog', i)
> if (i ne -1) then cnt = cnt + 1
> endwhile
> print, 'Found ',cnt, "occurances of 'dog'"
> end
> ------
>
> When I read it, it struck me as being wrong. I tested it later and it
> seems to have gone into an infinite loop (as I suspected it would). Is it
> some thing VERY obvious that I am missing or is it simply wrong?
>
> I am rather confused about this simple procedure. Any comments would be
> appreciated,
Yep, looks like an infinite loop to me. Needs the following line at
the end of the while loop:
i = i + strlen('dog') ; maybe i = i + 3 is faster ;-)
Dave
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
|
|
|