Login  Register

Re: Algorithmic issue

Posted by ctrueden on May 02, 2016; 5:12pm
URL: http://imagej.273.s1.nabble.com/Algorithmic-issue-tp5016298p5016301.html

Hi Philippe,

If you use one of the scripting languages instead of the macro language,
there are many ways with varying levels of elegance and obfuscation,
depending on your taste.

For example, here is an SO post discussing this issue for Python:
    http://stackoverflow.com/q/6981717/1207769

And here is some awesome stuff with Groovy:
    http://naleid.com/blog/2008/12/01/groovy-makes-iteration-easy

My personal taste regarding for+if is to eliminate the extra level of
indentation by using the "continue" keyword (or equivalent in whatever
language you are using), as in:

                boola = newArray(true, false, true, true, false);
                for(i = 0; i != boola.length; i++) {
                               if (!boola[i]) continue;
                               print(boola[i]);
                }

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - http://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - http://imagej.net/User:Rueden
Did you know ImageJ has a forum? http://forum.imagej.net/


On Mon, May 2, 2016 at 11:39 AM, Philippe CARL <[hidden email]>
wrote:

> Dear all,
>
> I would have a question that is not specifically ImageJ related, but rather
> with programming in general.
>
> Indeed, please consider the following macro code:
>
>                 boola = newArray(true, false, true, true, false);
>
>                 for(i = 0; i != boola.length; i++)
>
>                                if(boola[i])
>
>                                                print(boola[i]);
>
> Would there be a way to combine the for and if loops within a single one
> giving the same result than higher?
>
> I thank you very much in advance about your lighting concerning this
> question.
>
> My best regards,
>
> Philippe
>
>
>
> Philippe CARL
>
> Laboratoire de Biophotonique et Pharmacologie
>
> UMR 7213 CNRS - Université de Strasbourg
>
> Faculté de Pharmacie
>
> 74 route du Rhin
>
> 67401 ILLKIRCH
>
> Tel : +33(0)3 68 85 41 84
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html