Announcements

Announcement: We’re aware of an issue affecting starting a new topic from category pages and creating new blog posts. New topics can still be started directly from the relevant board. Learn more here.

How to use IF-ELSE condition and a proper use of brackets?!

How to use IF-ELSE condition and a proper use of brackets?!

francesco_v2
Not applicable
853 Views
5 Replies
Message 1 of 6

How to use IF-ELSE condition and a proper use of brackets?!

francesco_v2
Not applicable

[ FlexSim 19.2.0 ]

file-funzionante-base-difettoso.fsm

Hello, I would like some advice on how to use the if-else condition. I have wrotten the code of the alghorithm that I have attached.

When I use the only IF declaration the alghorithm work without problem but when I add the else condition, I have an error that declare that I didn't use the brackets in a proper way. I have checked many times but maybe I have some problem on how to use the IF-ELSE condition.

Thank you

Francesco

0 Likes
Accepted solutions (1)
854 Views
5 Replies
Replies (5)
Message 2 of 6

francesco_v2
Not applicable

I have talked about the ELSE in line 104.

0 Likes
Message 3 of 6

anthony_johnsonT83CM
Autodesk
Autodesk
Accepted solution

The following code is wrong:

else (solape> fracrepetidos2)

A straight else statement cannot have a condition. If you want a condition on the else, it should be an else if:

else if (solape > fracrepetidos2)
Message 4 of 6

joerg_vogel_HsH
Mentor
Mentor

The syntax is bit hidden in the manual, you find it under “Writing Logic in FlexSim”: Flow Constructs.

Message 5 of 6

francesco_v2
Not applicable

@anthony.johnson Do you know if si possible include a range of number in a IF condition?. I would like to have a condition that if a specific number is in a specific range, the IF condition is TRUE.

0 Likes
Message 6 of 6

mischa_spelt
Advisor
Advisor

You can use "&&" to check that multiple conditions are all true:

if(1 < x && x <= 10)

checks if "1 < x" and "x <= 10" are both true at the same time, which means that x is between 1 (exclusive) and 10 (inclusive).