-
Re: "if" revealed?
Thanks Eric for the help, now for him or any others who want to chime in...
Let's try and make this REAL clear...
First let us make this code easier to read.
1. String insert = $ClientLogo;
2. If ("$ClientLogo".equals(insert)){
3. a=b==d||e?f:g;
4. }else if{
5. {a=c;
6. }
Next, If I were to rewrite this code to make the precedence easier to follow,
would it look like this?
1. String insert = $ClientLogo;
2. If ("$ClientLogo".equals(insert)){
3. a=((b==d)||(e?f:g));
4. }else if{
5. {a=c;
6. }
Is this correct? Am I understanding the order of operations here?
If the order is correct then I believe this is what is happening.
First (b==d) is evaluated.
Second (e?f:g) is evaluated.
Third ((b==d)||(e?f:g)) is evaluated.
Fourth a=((b==d)||(e?f:g)) is evaluated.
Thanks for your patience. If I can get this part of the code figured out
I think I am almost home.
Mark
"Eric L" <eric.lett@creditunion.mb.ca> wrote:
>
>>5 if ("$ClientLogo".equals(insert)) {
>>6 replacement = null==logoPicName || "".equals(logoPicName.trim()) ? "
>" : "<IMG SRC=\"" + logoPicName + "\" ALIGN=center>";
>
>
>Ugly code, but I'll give it a shot.
>
>First, replacement is a String variable, and it is being assigned the HTML
>tag of the logoPicName.
>
>The ? operator is definatly being used. || is the short-circuit-or operator.
> logoPicName is also a String variable.
>
>So, if logoPicName==null, or logoPicName has not been set to a string, or
>
>".equals(logoPicName.trim()). "" indicates an empty string. String.trim
>removes all leading and trailing spaces in a string. This line checks to
>see if there is anything in the logoPicName variable.
>
>So, as far as I can understand it, this if statement checks to see if logoPicName
>is null, or an empty string, and sets Replacement to " " if true else set
>Replacement to the <IMG SCR> tag.
>
>This is my best guess. It is ugly code for a beginner to look at.
>
>Eric
-
Re: "if" revealed?
"Mark" <msorteberg@inspec.com> wrote:
>
>Thanks Eric for the help, now for him or any others who want to chime in...
>
>Let's try and make this REAL clear...
>
>First let us make this code easier to read.
>
>1. String insert = $ClientLogo;
>2. If ("$ClientLogo".equals(insert)){
>3. a=b==d||e?f:g;
>4. }else if{
>5. {a=c;
>6. }
>If the order is correct then I believe this is what is happening.
>First (b==d) is evaluated.
>Second (e?f:g) is evaluated.
>Third ((b==d)||(e?f:g)) is evaluated.
>Fourth a=((b==d)||(e?f:g)) is evaluated.
I hope this isn't actual production code. If it was, someone was really
looking for job security 
This is what I think, but I might be very wrong.
b==d||e? would be evaluated first. It is the first operand of ? operatior.
That would mean it would be evaluated as such:
((b==d))||e). If this is true, a is assigned f else a is assigned g. If
I was going to re-write the entire statement, I would do so as follows:
String Insert= $ClientLogo;
if ("$ClientLogo".equals(insert)) {
if ((b==d)||(e)) then
a=f
else
a=g
}
else
a=c
Syntactacly it might not be correct, but it is much easier to read. I personally
don't like the ? operatior. I find it can be confusing.
Eric
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks