Page 1 of 1

if then else problem

Posted: Fri Jun 15, 2007 12:53 am
by seshikumar
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

Re: if then else problem

Posted: Fri Jun 15, 2007 1:11 am
by srinath
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
res=a1+a2
else
if arg1='*' then
res=a1*a2
end
end
end


when i was compiling the code iam getting error
if Arg1= '+' or Arg1='-' then
res=a1+a2
end
else if Arg1='*' then
res=a1*a2
end

Posted: Fri Jun 15, 2007 1:55 am
by JKenklies
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):

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

Posted: Fri Jun 15, 2007 2:03 am
by JeroenDmt
you need to add two extra 'end' statements before the 'else'
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
Then it compiles correctly.

Posted: Fri Jun 15, 2007 2:26 am
by ray.wurlod
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.

Re: if then else problem

Posted: Fri Jun 15, 2007 2:33 am
by JoshGeorge
res = a1 arg1 a2

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

THis is routine

Posted: Fri Jun 15, 2007 2:45 am
by seshikumar
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.

Posted: Fri Jun 15, 2007 3:00 pm
by ray.wurlod
Is this in a routine or in a derivation expression? Your answer to that will affect what is the correct answer to your question.
:roll: