Hi Mohammad Your construction with list widgets is a pretty good approximation of a switch/case construction. The only frustration is that it is possible for a value to trigger more than one of the list widgets; it would be better if there was a way to make things stop after the first match.
One could certainly imagine a <$switch>/<$case> widget pair that could resolve that issue and might be more efficient as well. Perhaps after v5.1.20 Best wishes Jeremy > On 4 Jul 2019, at 10:06, Mohammad <[email protected]> wrote: > > In Javascript, C, C++ we have a programming construct called Switch-Case > > See : JS: https://www.w3schools.com/js/js_switch.asp > <https://www.w3schools.com/js/js_switch.asp>, > > switch(expression) { > case x: > // code block > break; > case y: > // code block > break; > default: > // code block > } > > > This code can do equivalent operation! Is this according to TW good > programming practice? > Is there any better solution? I think looking in list items may be another > solution! Does anybody has tried such solution before? > > > \define items() One Two [[Three Four]] Five > > \define switch(item) > <$list filter="[enlist<items>search<__item__>]" emptyMessage="Zero"> > <<currentTiddler>> > </$list> > \end > > <<switch One>> > <<switch "Three Four">> > <<switch "Ten">> > > > This line > > <$list filter="[enlist<items>search<__item__>]" emptyMessage="Zero"> > > Can be like this also > > <$list filter="[enlist<items>title<__item__>]" emptyMessage="Zero"> > > > What do you think? > > -- > You received this message because you are subscribed to the Google Groups > "TiddlyWiki" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > Visit this group at https://groups.google.com/group/tiddlywiki > <https://groups.google.com/group/tiddlywiki>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/tiddlywiki/b5fb6465-db3a-4809-a878-5b475f3c1b99%40googlegroups.com > > <https://groups.google.com/d/msgid/tiddlywiki/b5fb6465-db3a-4809-a878-5b475f3c1b99%40googlegroups.com?utm_medium=email&utm_source=footer>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/44FB1CAC-039E-4C67-88CA-3F81318F8A6D%40gmail.com. For more options, visit https://groups.google.com/d/optout.

