I noticed a simple ability to create "if" statements with the Decision block, but I can't figure out how to do multiple conditions without using multiple decision blocks.
In C, one can write an if statement with multiple else if's but I don't see that option here. Maybe the switch would be more useful?
Suggestions are appreciated.
-NGM
How to implement "else if" in Decision
Moderator: Benj
-
- Posts: 12
- Joined: Wed Jan 30, 2013 5:21 pm
- Has thanked: 1 time
- Contact:
-
- Posts: 12
- Joined: Wed Jan 30, 2013 5:21 pm
- Has thanked: 1 time
- Contact:
Re: How to implement "else if" in Decision
From the documentation it is looking like I do need to use the switch block, however operators like =, >, <, etc... don't seem to work here. In addition, only constants appear in the drop down, it does not list the Global variables.
This is what I thought would work, but my syntax is wrong:
The help file does not show any example usage.
-NGM
This is what I thought would work, but my syntax is wrong:
The help file does not show any example usage.
-NGM
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
- Contact:
Re: How to implement "else if" in Decision
Switch can only be used for single values, not ranges, just like the C equivalent. Multiple decision blocks can be nested, that is basically what you do in C as well
Is equivalent to adding two decision blocks, with code1 in the "yes" flow and the second decision in the "no".
Code: Select all
if ( condition ) {
code1;
} else if ( condition2 ) {
code2;
}
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: How to implement "else if" in Decision
Hello.
If you are familiar with C, and as you are using v5 it may help to have a look at the C code generated for decision blocks. You can drag the tabs to the right of the window or use the options in the 'Window' menu to create a split-view and see the C code along with the Flowchart.
There is an example showing C code viewing here:
[/youtube]
Cheers,
Jonny
If you are familiar with C, and as you are using v5 it may help to have a look at the C code generated for decision blocks. You can drag the tabs to the right of the window or use the options in the 'Window' menu to create a split-view and see the C code along with the Flowchart.
There is an example showing C code viewing here:
[/youtube]
Cheers,
Jonny
-
- Posts: 12
- Joined: Wed Jan 30, 2013 5:21 pm
- Has thanked: 1 time
- Contact:
Re: How to implement "else if" in Decision
So I basically need to hand code this in C? It's not that difficult, but I thought this would be a basic feature in Flowcode.
-NGM
-NGM
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
- Contact:
Re: How to implement "else if" in Decision
That is not what I was trying to tell you at all.
Question for you:
How would you code the following in C? (Flowcode equivalent will be provided after you've answered )
if i between 20 and 30 call subroutineA
else if i between 40 and 50, add 150 to i
else if i between 100 and 200, subtract 100 from i
Question for you:
How would you code the following in C? (Flowcode equivalent will be provided after you've answered )
if i between 20 and 30 call subroutineA
else if i between 40 and 50, add 150 to i
else if i between 100 and 200, subtract 100 from i
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
Re: How to implement "else if" in Decision
the best way IMO is using blocks
in your example.
it's easy in C codengmflowcode wrote:From the documentation it is looking like I do need to use the switch block, however operators like =, >, <, etc... don't seem to work here. In addition, only constants appear in the drop down, it does not list the Global variables.
This is what I thought would work, but my syntax is wrong:
The help file does not show any example usage.
-NGM
in your example.
Code: Select all
if(>0)
{
if(>26)
{
if(>50)
{
..........
(and so on...)
..........
}else{
(case 2)
}
}else{
(case 1)
}
}
- SteveM
- Posts: 55
- Joined: Tue Mar 25, 2014 2:09 pm
- Has thanked: 28 times
- Been thanked: 65 times
- Contact:
Re: How to implement "else if" in Decision
Hi all,
Nesting "if ... else if ... else if ... else ..." is quite simple using just the decision icons. The thing to remember is that the 'No' branch from the decision icons is equivalent to 'else' - anything you put in that branch is executed only when the condition is false. The structure ends up looking something like this...
Nesting "if ... else if ... else if ... else ..." is quite simple using just the decision icons. The thing to remember is that the 'No' branch from the decision icons is equivalent to 'else' - anything you put in that branch is executed only when the condition is false. The structure ends up looking something like this...