hi guys,
i have code like this aruments i dec arg1,a1,a2
if arg1= '+' then
res=a1+a2
else
if arg1='-' then
res=a1+a2
else
if arg1='*' then
res=a1*a2
end
end
end
when i was compiling the code iam getting error
if then else problem
Moderators: chulett, rschirm, roy
Re: if then else problem
if Arg1= '+' or Arg1='-' thenseshikumar wrote:hi guys,
i have code like this aruments i dec arg1,a1,a2
if arg1= '+' then
res=a1+a2
else
if arg1='-' then
res=a1+a2
else
if arg1='*' then
res=a1*a2
end
end
end
when i was compiling the code iam getting error
res=a1+a2
end
else if Arg1='*' then
res=a1*a2
end
God Gave Me Nothing I Wanted
He Gave Me Everything I Needed -- Swami Vivekananda
He Gave Me Everything I Needed -- Swami Vivekananda
I think you need an else clause at the end because the compiler needs to be sure, that in every situation you'll get some result.
What if arg1="crap"?
Saying your variable is called "someValue", the following example should work (delete the comments):
What if arg1="crap"?
Saying your variable is called "someValue", the following example should work (delete the comments):
Code: Select all
if arg1= '+' then
res=a1+a2
else
if arg1='-' then
res=a1-a2 // I bet this was a typo?
else
if arg1='*' then
res=a1*a2
else
someValue // this will be returned if arg1 not in (+,-,*)
Re: if then else problem
you need to add two extra 'end' statements before the 'else'
So it will be
Then it compiles correctly.
So it will be
Code: Select all
if arg1= '+' then
res=a1+a2
end
else
if arg1='-' then
res=a1+a2
end
else
if arg1='*' then
res=a1*a2
end
end
end
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Is this in a routine or in a derivation expression? Your answer to that will affect what is the correct answer to your question.
Please delete duplicate post.
Please delete duplicate post.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 612
- Joined: Thu May 03, 2007 4:59 am
- Location: Melbourne
Re: if then else problem
res = a1 arg1 a2
If my assumption below is right.
If my assumption below is right.
seshikumar wrote:hi guys,
i have code like this aruments i dec arg1,a1,a2
if arg1= '+' then
res=a1+a2
else
if arg1='-' then
<b> res=a1-a2 </b> **** Assuming this is a typo --> res=a1+a2
else
if arg1='*' then
res=a1*a2
end
end
end
when i was compiling the code iam getting error
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
-
- Participant
- Posts: 44
- Joined: Fri Mar 16, 2007 5:51 am
THis is routine
ray.wurlod wrote:Is this in a routine or in a derivation expression? Your answer to that will affect what is the correct answer to your question.
Please delete duplicate post.
seshu
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact: