This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can someone tell me why?

 
marcus conway
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Can someone tell me why--after i create a cube--it display 'enter test operation' twice?



[ November 17, 2008: Message edited by: Bear Bibeault ]
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's in a loop, so I'd assume that the loop is executed repeatedly. Check whether the loop termination condition works as you expect it to.

By the way, I'm almost positive that the getValue method does not work as you expect it to work. You may want to read about the "switch" statement, and what happens once one of the cases is matched.

Lastly, in the future UseAMeaningfulSubjectLine that states what the problem is.
[ November 17, 2008: Message edited by: Ulf Dittmer ]
 
marcus conway
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
That's in a loop, so I'd assume that the loop is executed repeatedly. Check whether the loop termination condition works as you expect it to.

By the way, I'm almost positive that the getValue method does not work as you expect it to work. You may want to read about the "switch" statement, and what happens once one of the cases is matched.

Lastly, in the future UseAMeaningfulSubjectLine that states what the problem is.

[ November 17, 2008: Message edited by: Ulf Dittmer ]


Is it because I'm using the getValue() switch statement on chars?

Thanks for your help
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, chars work fine in switch statements. Ask yourself this: Suppose getFace() returns 't', causing "val = 1;" to be executed. Now, what is the next statement that gets executed? And consequently, which value of "val" will be returned from the method?
 
marcus conway
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
No, chars work fine in switch statements. Ask yourself this: Suppose getFace() returns 't', causing "val = 1;" to be executed. Now, what is the next statement that gets executed? And consequently, which value of "val" will be returned from the method?


how bout this?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Ulf was hinting you should read about the break keyword in a switch statement
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FAQ: Use A Meaningful Subject Line

welcome,

history note:
the good ol' switch statement comes down to us from the C programming language, the first step up from assembly programming, and as such still requires a little bit more work to do what you want it to,

(i.e. check on the break keyword as suggested above - and/or trace through the debugger and see how it's executing)
[ November 17, 2008: Message edited by: Bill Shirley ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic