Re: Hints & Tips

new topic     » goto parent     » topic index » view thread      » older message » newer message

Carl R. White wrote:
> 2) Ever coded something like this?:
>         flag = 0
>         for i = 1 to length(seq)
>             if seq[i] = 'a' or seq[i] = 'b' or seq[i] = 'z' then
>                 flag = 1
>                 --exit --maybe
>             end if
>         end for
>
>         if flag then ... etc.
>
> 4) Expanding from the above:
>    If you have to code a loop that runs through a sequence an element
>    at a time, there's probably a way of getting Euphoria to do the hard
>    work for you by using a function that treats sequences like atoms.

it should cause euphoria to do the hard work for you if you replaced all
of the above
with this one single line, which reads rather well i think, and *should*
be
exceptionally fast, perhaps even faster than walking all the way thru
the sequence
an element at a time since its pseudo-slicing and examining a sequence
all at once.
note: find returns 0 if not found or a number > 0 indicating the
location
        within the sequence where target is found. now, since not-zero is
TRUE...

flag = ( find('a',seq) or find('b',seq) or find('z',seq) )

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu