• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does Java have an equivalent of a COBOL Evaluate Statement?

 
Rudolph Ten
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does Java have an equivalent of a COBOL Evaluate Statement?
Lets say I want to keep track of Grades.
I would Evaluate Each GRADE for true...top to bottom....once found would exit.
Evalute True
....When Grade = "A"
Add 1 to A-cnt.
....When Grade = "B"
Add 1 to B-cnt.
....When Grade = "C"
Add 1 to C-cnt.
....When Grade = "D"
Add 1 to D-cnt.
....When Other
Add 1 to Invalid-grade-cnt.
End-evaluate.
-----------------------
If/else statemnts in Java are Ugly to me(maybe cause i am knew to it)....having trouble knowing whats if applies to what... and yes.... i am aligning my 'if's, 'else's, '{'s, '}'s. Am also using comments....but....
I miss END-IF Statement....
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have u considered a switch case statament??
like this:
char grade='c';
switch (grade)
{
case 'a':
a-cnt+=1;
break;
case 'b':
b-cnt+=1;
break;
}
etc...
 
Rudolph Ten
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks...
Is a set of X IF statements more efficient then a Switch Statement with X cases in it? are they the same?
 
Michael Matola
whippersnapper
Ranch Hand
Posts: 1817
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rudolph Ten:
If/else statemnts in Java are Ugly to me(maybe cause i am knew to it)....having trouble knowing whats if applies to what... and yes.... i am aligning my 'if's, 'else's, '{'s, '}'s. Am also using comments....but....

Take a look at the some of the recommended formatting practices in the JavaRanch style guide.
I think following these conventions (among other benefits) helps make conditional logic clear.
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
both have the same efficiency.
all depends on what is easier for u.
in this case i think switch case is the ideal solution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic