View previous topic :: View next topic |
Author |
Message |
hemamfuser Beginner
Joined: 09 May 2006 Posts: 9 Topics: 3
|
Posted: Thu May 11, 2006 9:19 am Post subject: label not being called properly in PLI |
|
|
Hai Members,
I have a very basic question in PLI and my code looks like below:
The value of A > B , the label executes and displays HAI.
Code: |
PROG1:PROCEDURE OPTIONS(MAIN);
DCL A FIXED DEC INIT (0);
DCL B FIXED DEC INIT (0);
A = 50;
B = 10;
CALL PROCA;
PROCA: PROC;
IF A > B THEN
GO TO WORK;
WORK:
PUT SKIP LIST('HAI');
END PROCA;
END PROG1;
|
OUTPUT
Now i change the value of A by making less than B .If the value of A less than B ,the label still executes and display HAI.The condition is not met and why is the label called.Can anybody help me out as i am quite new to PLI ? In PLI a label is called irrespective of the condition : So in my case the label will be called always whenever the PROCA is called ? Please correct me in my understanding and correct me if i am wrong .
Code: |
PROG1:PROCEDURE OPTIONS(MAIN);
DCL A FIXED DEC INIT (0);
DCL B FIXED DEC INIT (0);
A = 5;
B = 10;
CALL PROCA;
PROCA: PROC;
IF A > B THEN
GO TO WORK;
WORK:
PUT SKIP LIST('HAI');
END PROCA;
END PROG1;
|
OUTPUT
|
|
Back to top |
|
 |
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Thu May 11, 2006 11:28 am Post subject: |
|
|
A label by itself does not ensure conditional execution. You would have to 'escape' it. Something as follows:
Code: |
PROCA: PROC;
IF A > B THEN
GO TO WORK
ELSE
GO TO NOWORK;
WORK:
PUT SKIP LIST('HAI');
NOWORK:
END PROCA;
|
_________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
 |
hemamfuser Beginner
Joined: 09 May 2006 Posts: 9 Topics: 3
|
Posted: Thu May 11, 2006 1:11 pm Post subject: |
|
|
Thanks for your reply.But why in the example label WORK is being executed , as per the condition A is less than B ,so the label should not execute and PUT SKIP LIST statement shoud not execute at all and there will be no output for the program.Can i have some information on this please ? |
|
Back to top |
|
 |
Mervyn Moderator

Joined: 02 Dec 2002 Posts: 415 Topics: 6 Location: Hove, England
|
Posted: Thu May 11, 2006 2:13 pm Post subject: |
|
|
Cogito is absolutely correct.
WORK is executed because you have done nothing to cause it NOT to be executed. Your code simply "drops" into the "PUT" code.
Have you actually tried Cogito's code?
This would work, too:
Code: |
PROCA:
PROC;
IF A <= B THEN
PUT SKIP LIST('HAI');
END PROCA;
|
_________________ The day you stop learning the dinosaur becomes extinct |
|
Back to top |
|
 |
|
|