aspose file tools*
The moose likes Beginning Java and the fly likes Does Java have an equivalent of a COBOL Evaluate Statement? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Does Java have an equivalent of a COBOL Evaluate Statement?" Watch "Does Java have an equivalent of a COBOL Evaluate Statement?" New topic
Author

Does Java have an equivalent of a COBOL Evaluate Statement?

Rudolph Ten
Greenhorn

Joined: Jan 23, 2002
Posts: 9
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

Joined: Jan 13, 2002
Posts: 732
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

Joined: Jan 23, 2002
Posts: 9
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

Joined: Mar 25, 2001
Posts: 1749
    
    2
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

Joined: Jan 13, 2002
Posts: 732
both have the same efficiency.
all depends on what is easier for u.
in this case i think switch case is the ideal solution.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does Java have an equivalent of a COBOL Evaluate Statement?