Hi all again,
in addition to the problem I described in my last post I also have the problem that if-conditions are ignored in several parts of my code such as the following snippet: if(Roundness!="0.00-1.00" & end==false) { double RoundnessMin = Double.parseDouble(Roundness.substring(0, Roundness.indexOf("-"))); double RoundnessMax = Double.parseDouble(Roundness.substring(Roundness.indexOf("-")+1)); if(resultsTable.getValue("Round", n)<RoundnessMin || resultsTable.getValue("Round", n)>RoundnessMax) { filledImage.fill8(X[n], Y[n]); end=true; IJ.log("Roundness"); } } The statement should only be done if: Roundness!="0.00-1.00" (which is defined by a prior dialog) AND if end==false. Problem is that the statement is also performed when Roundness exactly is "0.00-1.00". I read that Java is normally checking from left to right and stops checking conditions if one is met. Is this the case? Furthermore, I tried other operators (&& and || and |) and several different bracket settings but none was able to block the program from running the code. Any suggestions where my assumptions are wrong or how to specify the condition to be able to block running the statement. Thanks in advance, Jan -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Jan,
> if(Roundness!="0.00-1.00" & end==false) { You almost certainly want to be using "&&" for logical and, rather than "&" (bitwise AND). http://stackoverflow.com/q/4014535 You almost certainly want to compare strings with "!s.equals(s2)" rather than "s != s2" since string comparison using the equality operator only works in certain very special cases (two string objects with the same content but different references will not test as equal). http://stackoverflow.com/q/513832 Also, I suggest writing "!end" rather than "end==false". Regards, Curtis On Fri, May 9, 2014 at 10:45 AM, BioVoxxel <[hidden email]> wrote: > Hi all again, > > in addition to the problem I described in my last post I also have the > problem that if-conditions are ignored in several parts of my code such as > the following snippet: > > if(Roundness!="0.00-1.00" & end==false) { > > double RoundnessMin = Double.parseDouble(Roundness.substring(0, > Roundness.indexOf("-"))); > double RoundnessMax = > Double.parseDouble(Roundness.substring(Roundness.indexOf("-")+1)); > if(resultsTable.getValue("Round", n)<RoundnessMin || > resultsTable.getValue("Round", n)>RoundnessMax) { > > filledImage.fill8(X[n], Y[n]); > > end=true; > > IJ.log("Roundness"); > > } > > } > > The statement should only be done if: Roundness!="0.00-1.00" (which is > defined by a prior dialog) AND if end==false. > Problem is that the statement is also performed when Roundness exactly is > "0.00-1.00". > > I read that Java is normally checking from left to right and stops checking > conditions if one is met. Is this the case? > > Furthermore, I tried other operators (&& and || and |) and several > different bracket settings but none was able to block the program from > running the code. > > Any suggestions where my assumptions are wrong or how to specify the > condition to be able to block running the statement. > > Thanks in advance, > Jan > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Gabriel, Hi Curtis,
Thanks for your advice and the links (which I didn't find during my search). I will try if I get it running by changing all accordingly. Have a nice weekend, Jan 2014-05-09 18:35 GMT+02:00 Curtis Rueden <[hidden email]>: > Hi Jan, > > > if(Roundness!="0.00-1.00" & end==false) { > > You almost certainly want to be using "&&" for logical and, rather than > "&" (bitwise AND). http://stackoverflow.com/q/4014535 > > You almost certainly want to compare strings with "!s.equals(s2)" rather > than "s != s2" since string comparison using the equality operator only > works in certain very special cases (two string objects with the same > content but different references will not test as equal). > http://stackoverflow.com/q/513832 > > Also, I suggest writing "!end" rather than "end==false". > > Regards, > Curtis > > > On Fri, May 9, 2014 at 10:45 AM, BioVoxxel <[hidden email]>wrote: > >> Hi all again, >> >> in addition to the problem I described in my last post I also have the >> problem that if-conditions are ignored in several parts of my code such as >> the following snippet: >> >> if(Roundness!="0.00-1.00" & end==false) { >> >> double RoundnessMin = Double.parseDouble(Roundness.substring(0, >> Roundness.indexOf("-"))); >> double RoundnessMax = >> Double.parseDouble(Roundness.substring(Roundness.indexOf("-")+1)); >> if(resultsTable.getValue("Round", n)<RoundnessMin || >> resultsTable.getValue("Round", n)>RoundnessMax) { >> >> filledImage.fill8(X[n], Y[n]); >> >> end=true; >> >> IJ.log("Roundness"); >> >> } >> >> } >> >> The statement should only be done if: Roundness!="0.00-1.00" (which is >> defined by a prior dialog) AND if end==false. >> Problem is that the statement is also performed when Roundness exactly is >> "0.00-1.00". >> >> I read that Java is normally checking from left to right and stops >> checking >> conditions if one is met. Is this the case? >> >> Furthermore, I tried other operators (&& and || and |) and several >> different bracket settings but none was able to block the program from >> running the code. >> >> Any suggestions where my assumptions are wrong or how to specify the >> condition to be able to block running the statement. >> >> Thanks in advance, >> Jan >> >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html >> > > -- CEO: Dr. rer. nat. Jan Brocher phone: +49 (0)6234 917 03 39 mobile: +49 (0)176 705 746 81 e-mail: [hidden email] info: [hidden email] inquiries: [hidden email] web: www.biovoxxel.de -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |