03-23-2020 03:29 AM
Hi,
i want your help , i am going to create a program this program have 16 cas structure ( if x true ….. else if false …) is there another way to make this program without using so many case structure .
Thank you for your answer .
Best Regard.
03-23-2020 03:50 AM
03-23-2020 04:08 AM - edited 03-23-2020 04:09 AM
If it's all boolean cases, you can create an array and convert to number, thus only having 1 case structure with more cases instead of many nested ones.
03-23-2020 05:00 AM
@Emna20 wrote:
Hi,
i want your help , i am going to create a program this program have 16 cas structure ( if x true ….. else if false …) is there another way to make this program without using so many case structure .
If then .. else .. else ...
This does not require nested case structures, it's simply several cases in one case structure.
if a==1 then ...
else if a ==2...
else if a ==3...
else if a ==4...
One structure with multiple cases
if a==1 then
...
else if b ==1 then
...
else if c ==3 then
...
else if a ==4 then
...
4 nested case structures...
Nested structures should be limitted. The way to avoid this depends very much on the details.
03-23-2020 07:15 AM
This is another example where attaching your code would have resulted in a very speedy answer and "teaching demonstration" of "an alternate way of thinking" about this problem. We don't know what your Cases actually involve. If it involves a choice between a small subset of a larger set (say, a choice if an integer, call it "N", is 1, 2, 3, ... 16), you can make a Case Statement with N wired into the "?" input, and Cases for 1 .. 16. But this Case Statement will be "broken" because you don't have a Case for all possible Values (for example, no "17" case, and no "-1234" case). This is where the "Default" case comes in handy (think of it as the "ultimate Else". You can either program 16 "correct" cases and leave "Default" to send an Error Message ("Unexpected Case"), or you can have a Case "1, Default".
Look at the JKI State Machine, which uses Strings for State names. The Default is an Error message saying "Unexpected State" (or something like that). [The alternative State choice, an Enum, creates a pre-determined finite set of States, so you only need as many Case Statements as you have States, and no Default is needed].
Bob Schor
03-23-2020 09:42 AM
Hi,
Thank you for your response .
you find below the program ,
Best Regard.
03-23-2020 09:48 AM
Here is One way to avoid the nested case structures...
03-23-2020 09:50 AM
That is scary. Don't do it like that!
I you have 4 booleans, you have 16 combinations. So convert the 4 booleans to an array, convert the array to number. Wire the number to case selector.
Add a case for each of those numbers.
If there are groups of similar things to execute (for instance if the 2nd boolean is true) you might end up with a few parallel case structures.
03-23-2020 09:53 AM
Pretty sure wiebe was talking about the original code... not the cod snippet I posted. LOL
(IE his description is the code I posted)
03-23-2020 09:59 AM