Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » if expression
if expression [message #1758089] Thu, 23 March 2017 12:29 Go to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 261
Registered: July 2016
Senior Member
I have the below code, if I want to add one if condition before "if condition2" without else part what can I do?
if condition1
then
	exp1
else
       if condition2
       then
	        exp2
        else  
                exp3
      endif
endif;

if I do something like below, I have a syntax error("expected else").
if condition1
then
	exp1
else
       if extra condition
       then       if condition2
                        then
	                exp2
                        else  
                        exp3
                        endif
      endif
endif;

"extra condition" ensures that "condition2" is defined.

[Updated on: Thu, 23 March 2017 12:36]

Report message to a moderator

Re: if expression [message #1758095 is a reply to message #1758089] Thu, 23 March 2017 13:55 Go to previous messageGo to next message
louis andia. is currently offline louis andia.Friend
Messages: 46
Registered: November 2016
Member
No you can't. You have to define what happen if your extra condition isn't true. So it will probably be that in your case:
if condition1
then
	exp1
else
       if extra condition
       then       if condition2
                        then
	                exp2
                        else  
                        exp3
                        endif
      else  
       exp3
      endif
endif;
Re: if expression [message #1758119 is a reply to message #1758095] Thu, 23 March 2017 17:06 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 261
Registered: July 2016
Senior Member
Thanks for your kind help. My "exp3" has also many "if-then-else" expressions, is there any other idea?
Re: if expression [message #1758120 is a reply to message #1758119] Thu, 23 March 2017 17:12 Go to previous messageGo to next message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 261
Registered: July 2016
Senior Member
In imperative part, I do something like this:
helper def : a : Boolean= false;
thisModule.a <- cond 1;	
if (cond 2)
{
	thisModule.a <-  thisModule.a + cond 3;
}

if ( thisModule.a){
....
}

Is it true?

[Updated on: Thu, 23 March 2017 19:46]

Report message to a moderator

Re: if expression [message #1758128 is a reply to message #1758120] Thu, 23 March 2017 18:33 Go to previous messageGo to next message
louis andia. is currently offline louis andia.Friend
Messages: 46
Registered: November 2016
Member
Your 'exp3' can be an helper to avoid code duplication.
Re: if expression [message #1758142 is a reply to message #1758128] Thu, 23 March 2017 19:44 Go to previous message
Banafsheh A is currently offline Banafsheh AFriend
Messages: 261
Registered: July 2016
Senior Member
Thank you
Previous Topic:[to delete]
Next Topic:second element of sequence
Goto Forum:
  


Current Time: Sun Nov 19 18:17:02 GMT 2017

Powered by FUDForum. Page generated in 0.01840 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software