View previous topic :: View next topic
|
Author |
Message |
sutirtha mukherjee
New User
Joined: 04 Mar 2008 Posts: 6 Location: Chennai
|
|
|
|
Hi,
Can anyone help me out of this..
I ran a strobe request and it is pointing to a section of code where
i have used a IF statement with 2 else and a lot of OR and AND conditinos
i.e.
if var1 = 1 or 3 and var2 = 3 or 6
else if condition with many or/and
My question is if use a switch instead or the var1 or variable will i get a performance boost? |
|
Back to top |
|
|
rajesh_mbt
New User
Joined: 27 Mar 2006 Posts: 97 Location: India
|
|
|
|
Hi Sutirtha,
It is advisable that you use switch statement instead of nested if. Since, some compilers will not support more than 4 or 5 nested level. Also, the code looks simple and understandable easily while using switch statement.
In the switch you can use and/ or as your requirement. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
I have been around IT for a day or two, but this one has me. What language has a SWITCH command? what is a SWITCH command? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10889 Location: italy
|
|
|
|
switch is a C ( maybe JAVA ) construct
Code: |
switch (variable) {
case expression1:
..... ;
break;
case expression2:
..... ;
break;
case expression3:
..... ;
break;
default:
...... ;
} |
|
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
How about a COBOL EVALUATE?
It's easy to maintain and even easier to comprehend.
Many times, maintenance causes well-intentioned "IF-THEN-ELSE" constructs to wind up looking looking like a Chinese menu (no offence implied), causing programmers to apply some "creative" code.
As most of us have been around the block a few times, I myself have had to resort to generating the ASSEMBLER expansion of a COBOL program, because the logic has become so convoluted, it's the only way it can be followed.
When you have an "IF" ending in 6 right-parenthesis, embedded with OR's and AND's, as well as other nested "IF"'s and "ELSE"s, it's time for review and apply a different approach.
Just my .02 cents....
Regards,
Bill |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
As far as I know MAINFRAME cobol doesn't have a switch! |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
Hi,
EVALUATE should work for Your scenario..try the below feacture of EVALUATE
Code: |
EVALUATE TRUE ALSO TRUE |
Check the manuals please, it should be doable. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
On many of the systems i've supported the "switch" is just a field that can be turned "on" or "off" and then tested in the code. Many have 88 levels to use a name rather than a value (i.e. "if switch-on. . ." rather than "if swiotch-field = 1). |
|
Back to top |
|
|
rajesh_mbt
New User
Joined: 27 Mar 2006 Posts: 97 Location: India
|
|
|
|
Hi All,
Sorry for the confusion... I knew in cobol there is no switch statement like c/c++/java.... In my reply I mentioned Evaluate statement as switch. Since, he had mentioned as switch and I simply followed it . |
|
Back to top |
|
|
sutirtha mukherjee
New User
Joined: 04 Mar 2008 Posts: 6 Location: Chennai
|
|
|
|
sorry all ,
i created the confusion ...
actually i intended to ask this:
var pic s9(4) comp. (mine is a comp variable)
"if var = 2
imperative statement"
would perform better
OR
var value 1
88 var-flag pic x value 1
"if var-flag
imperative statement"
would perform better ?
(NOTE:i am using only the variable for comparision only no arithmetic operations) |
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
I prefer second one. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
Bill -
Your opinions are worth much more than 2/100 of a cent to me. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
would perform better ? |
It would be difficult to measure the difference as they are both "the same".
If you look at the generated assembler, you will be able to see the actual code.
Quote: |
Your opinions are worth much more than 2/100 of a cent to me |
Me too - at least 19/100 of a cent. . . |
|
Back to top |
|
|
|