﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Millisecond Forums » Millisecond Forums » Inquisit 4  » Nested Conditionals (If Else)</title><generator>InstantForum 2017-1 Final</generator><description>Millisecond Forums</description><link>https://forums.millisecond.com/</link><webMaster>Millisecond Forums</webMaster><lastBuildDate>Sat, 30 May 2026 12:10:53 GMT</lastBuildDate><ttl>20</ttl><item><title>Nested Conditionals (If Else)</title><link>https://forums.millisecond.com/Topic15321.aspx</link><description>Hi!&amp;nbsp;&lt;br/&gt;&lt;br/&gt;I've been scratching my head a bit since I couldn't figure out why my code wasn't doing what I expected.&amp;nbsp;&lt;br/&gt;After a bit of testing it seems to me that embedding IF conditionals within and IF-THEN-ELSE conditional leads to unwanted results, that is, the ELSE statement is not evaluated, could you confirm this?&amp;nbsp;&lt;br/&gt;&lt;br/&gt;For instance, this works fine (value.g is set to 255)&lt;br/&gt;&lt;blockquote&gt;&amp;nbsp;if(0) {values.r = 0; values.g = 0; values.b = 255} &amp;nbsp;else {values.r = 0;&amp;nbsp;values.g = 255, values.b = 0;};&lt;/blockquote&gt;&lt;br/&gt;However, this doesn't work (value.g is never set)&lt;br/&gt;&lt;blockquote&gt;&amp;nbsp;if(0) { if(1) {values.r = 0; values.g = 0; values.b = 255}; } &amp;nbsp;else {values.r = 0;&amp;nbsp;values.g = 255, values.b = 0;};&lt;/blockquote&gt;&lt;blockquote&gt;&lt;br/&gt;&lt;/blockquote&gt;To be clear, the code doesn't crash / break or give warnings, it's just that the else expression is never evaluated.&amp;nbsp;&lt;br/&gt;&lt;br/&gt;Is there anything that I might be missing here? I tried different semicolon placements, but it didn't seem to make a difference.&lt;br/&gt;&lt;br/&gt;Thanks,&lt;br/&gt;&lt;br/&gt;Kerwin&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;</description><pubDate>Sat, 10 Jan 2015 01:47:16 GMT</pubDate><dc:creator>Kolfers</dc:creator></item><item><title>RE: Nested Conditionals (If Else)</title><link>https://forums.millisecond.com/Topic15324.aspx</link><description>Thanks for the reply!&amp;nbsp;&lt;br/&gt;&lt;br/&gt;I agree that most things can be rewritten (although sometimes it means a sizeable increase in code length), I just needed to be sure that this was indeed the problem.&amp;nbsp;&lt;br/&gt;&lt;br/&gt;The&amp;nbsp;&lt;strong&gt;else 0 &lt;/strong&gt;option would provide the quickest workaround for now, thanks!&amp;nbsp;&lt;br/&gt;&lt;br/&gt;cheers,&lt;br/&gt;&lt;br/&gt;Kerwin</description><pubDate>Sat, 10 Jan 2015 01:47:16 GMT</pubDate><dc:creator>Kolfers</dc:creator></item><item><title>RE: Nested Conditionals (If Else)</title><link>https://forums.millisecond.com/Topic15323.aspx</link><description>The expressions parser doesn't particularly like nested conditionals along those lines, yes. It will fail to fully parse the expression when stated as you did and will not ever "see" the relevant else. You can force the parser into submission by restating to e.g.&lt;br/&gt;&lt;br/&gt;&amp;lt;values&amp;gt;&lt;br/&gt;/ r = -1&lt;br/&gt;/ g = -1&lt;br/&gt;/ b = -1&lt;br/&gt;/ c = false&lt;br/&gt;&amp;lt;/values&amp;gt;&lt;br/&gt;&lt;br/&gt;&amp;lt;trial set1&amp;gt;&lt;br/&gt;/ ontrialbegin = [if(false) {values.r = 0; values.g = 0; values.b = 255} else &lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {values.r = 0; values.g = 255; values.b = 0};&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ]&lt;br/&gt;/ ontrialend = [values.r = 0; values.g = 0; values.b = 0]&lt;br/&gt;/ stimulusframes = [1=mytext]&lt;br/&gt;/ validresponse = (57)&lt;br/&gt;&amp;lt;/trial&amp;gt;&lt;br/&gt;&lt;br/&gt;&amp;lt;trial set2&amp;gt;&lt;br/&gt;&lt;strong&gt;/ ontrialbegin = [if(false) {if(true){values.r=0; values.g=0; values.b=255} else 0;} else &lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {values.r = 0; values.g = 255; values.b = 0};&lt;br/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ]&lt;/strong&gt;&lt;br/&gt;/ ontrialend = [values.r = 0; values.g = 0; values.b = 0]&lt;br/&gt;/ stimulusframes = [1=mytext]&lt;br/&gt;/ validresponse = (57)&lt;br/&gt;&amp;lt;/trial&amp;gt;&lt;br/&gt;&lt;br/&gt;&amp;lt;text mytext&amp;gt;&lt;br/&gt;/ items = ("R=&amp;lt;%values.r%&amp;gt;|G=&amp;lt;%values.g%&amp;gt;|B=&amp;lt;%values.b%&amp;gt;")&lt;br/&gt;&amp;lt;/text&amp;gt;&lt;br/&gt;&lt;br/&gt;&amp;lt;block myblock&amp;gt;&lt;br/&gt;/ trials = [1=set1; 2=set2]&lt;br/&gt;&amp;lt;/block&amp;gt;&lt;br/&gt;&lt;br/&gt;In most cases, though, I would argue that there's a different and perhaps "better" way to express whatever you want to do (e.g. using if - else if - else constructs or collapsing the conditionals). Hope this helps.&lt;br/&gt;</description><pubDate>Fri, 09 Jan 2015 16:57:56 GMT</pubDate><dc:creator>Dave</dc:creator></item></channel></rss>