Results 1 to 11 of 11
- 12-21-2008, 05:29 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 6
- Rep Power
- 0
[SOLVED] need help with logic operator
hello all
i'm a newbie in java
actually i'm a c++ programmer
but now i think i need help
i have this code in c++:
while((h = hashTab[++j].Key) && (h - HashKeyHi && --i));
all variables are integer
i've got this error message:
operator && cannot be applied to int,int
well, i guess that's why i love c++ so much... :D
any idea what should i do?
how can i deal with this && operator in java?
thanks all...!!!
-
ints can't substitute for booleans in Java as they can in C++. You'll need to put some == and != in there to make it work.
- 12-21-2008, 08:19 AM #3
Member
- Join Date
- Dec 2008
- Posts
- 6
- Rep Power
- 0
ahh... now i know..
you inspired me...
while(true){
if((h = hashTab[++j].Key) == 0
|| (h - HashKeyHi) == 0
|| (--i) == 0)
break;
}
thanks fubarable...
now i know why i love c++...
:)
- 12-21-2008, 04:12 PM #4
May not...
Your initial logic indicated logic "and", yet you implemnted it with logic "or". Shouldn't your code be:
Luck,Java Code:while(true){ if((h = hashTab[++j].Key) == 0 [B][COLOR="Red"]&&[/COLOR][/B] (h - HashKeyHi) == 0 [B][COLOR="red"]&&[/COLOR][/B] (--i) == 0) break; }
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-21-2008, 04:36 PM #5
Member
- Join Date
- Dec 2008
- Posts
- 6
- Rep Power
- 0
I don't think so...
first: operator && will return 0 if at least one operand value is zero...
second:looking at my first code... i want it to break out of while loop if at least one of these condition is zero:
-> h = hashTab[++j].Key
-> h - HashKeyHi
-> --i
third: that's why i compare them with zero and use or...
fourth: your code will execute break if all conditions are zero...
fifth: i've tried it... :)
sixth: thanks a lot for your feedback...
i really-really appreciate it...
:D
- 12-21-2008, 05:23 PM #6
huh...
I'm not sure we're on the same frecuency here... If the code is doing what you want it to do, then great, but you're statements of logic are not right...
The the above statements say the same thing.first: operator && will return 0 if at least one operand value is zero...
second:looking at my first code... i want it to break out of while loop if at least one of these condition is zero:
-> h = hashTab[++j].Key
-> h - HashKeyHi
-> --i
The "compare with zero" part I agree with, but the "or" part I do not agree with. With "or" all the comparasion statements have to be != 0 before it the while breaks out.third: that's why i compare them with zero and use or...
Not so... using "&&" is the same condition as the above points one and two.fourth: your code will execute break if all conditions are zero...
Again, if it's working the way you want it to, that's good.fifth: i've tried it...
Luck,
CJSL
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-22-2008, 05:30 AM #7
Member
- Join Date
- Dec 2008
- Posts
- 6
- Rep Power
- 0
- 12-22-2008, 02:24 PM #8
My head hurts
Yes, again, I agree with you that with "or" if you have one true statement in your "if", the whole statement is true, but I thought you were look for conditions to "break" out of the "while" loop using "and" logic (as your original code stated).
Before I go on with this discussion (apparently pointless), you want ALL the condition statements to be false (!=0), before you break out of the loop, correct?
Thanks,Java Code:while(true){ if((h = hashTab[++j].Key) == 0 || (h - HashKeyHi) == 0 || (--i) == 0) break; }
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-24-2008, 03:36 AM #9
Member
- Join Date
- Dec 2008
- Posts
- 6
- Rep Power
- 0
yup....
:D
- 12-24-2008, 02:34 PM #10
ok...
Glad it's working for you...
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-25-2008, 10:01 PM #11
Member
- Join Date
- Dec 2008
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
Separating program logic and GUI
By loopingman in forum AWT / SwingReplies: 0Last Post: 12-08-2008, 02:46 PM -
Logic to generate a pattern
By vijay_2008 in forum Advanced JavaReplies: 3Last Post: 11-23-2008, 02:40 AM -
Logic Error: Not Writing To File
By JDCAce in forum Advanced JavaReplies: 6Last Post: 10-21-2008, 02:13 AM -
Cant get the logic right
By jermaindefoe in forum New To JavaReplies: 4Last Post: 03-11-2008, 12:22 AM -
iterate HashMap with logic
By Heather in forum Web FrameworksReplies: 2Last Post: 07-03-2007, 09:47 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks