{"id":67,"date":"2009-02-04T08:49:36","date_gmt":"2009-02-04T06:49:36","guid":{"rendered":"http:\/\/www.coolbasic.com\/blog\/?p=67"},"modified":"2009-02-04T08:49:36","modified_gmt":"2009-02-04T06:49:36","slug":"assigning-stuff","status":"publish","type":"post","link":"https:\/\/www.coolbasic.com\/blog\/2009\/02\/04\/assigning-stuff\/","title":{"rendered":"Assigning stuff"},"content":{"rendered":"<p>C-languages (and the like) make difference between the &#8220;assign&#8221; operator and the &#8220;comparison: equal&#8221; operator, as opposed to BASIC-languages where both share the same symbol. The other assign operators such as &#8220;<code>+=<\/code>&#8220;, &#8220;<code>-=<\/code>&#8220;, &#8220;<code>*=<\/code>&#8221; and &#8220;<code>\/=<\/code>&#8220;, in comparison, operate the same way in both languages &#8211; almost. In C-languages you can use assign operators pretty much anywhere within expressions because unlike in BASIC-languages, they return the value that was just assigned. That&#8217;s why you can use &#8220;<code>a=b=c=1<\/code>&#8221; in C, and have all the three variables be assigned a value of 1. In BASIC-languages, where symbol &#8220;<code>=<\/code>&#8221; defines the comparison operator, the same statement would equal C-expression of &#8220;<code>a=(b==c==1)<\/code>&#8221; which would result in a boolean value of <code>True<\/code> or <code>False<\/code> to be assigned to variable a, depending on the values of b and c.<\/p>\n<p>The problem in BASIC-langages is that the compiler can&#8217;t tell whether the user wanted to express an assignment or a comparison with symbol &#8220;<code>=<\/code>&#8220;, except for the first one in line; the rest are considered &#8220;comparison: equal&#8221;. BASIC-language parsers typically distinguish these two operators (that share the same symbol) by context: Are we expecting a value here or not. Therefore, by design, BASIC-language assign operators don&#8217;t return a value. Unfortunately, nor do any of the other assign operators: &#8220;<code>+=<\/code>&#8220;, &#8220;<code>-=<\/code>&#8220;, etc. because of consistency. Thus you can&#8217;t do loop auto increments like:<\/p>\n<p><code>While ((myVar += 1) &lt; 10)<\/code><\/p>\n<p>In addition, since no value is evaluated by the assignment you can&#8217;t have the operation applied before\/after evaluation, like the &#8220;<code>++<\/code>&#8221; and &#8220;<code>--<\/code>&#8221; operators in C do (they can appear before or after a variable). In addition, the &#8220;<code>--<\/code>&#8221; as prefix has also a double meaning: it can either be decrement before evaluation, or a double unary minus. Too much noice here. And that&#8217;s why those operators are missing from most BASIC-languages including VB.NET &#8211; and they won&#8217;t make it to CoolBasic either. You will be able to use &#8220;<code>i += 1<\/code>&#8220;, but not within a value expression.<\/p>\n<p>In summary, these are the assign operators that will be implemented to CoolBasic V3:<br \/>\n<code>\"=\", \"+=\", \"-=\", \"*=\", \"\/=\", \"&lt;&lt;=\"<\/code> and <code>\"&gt;&gt;=\"<\/code>.<\/p>\n<p><strong>Edit 15.5.2009:<\/strong> Fixed typos.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C-languages (and the like) make difference between the &#8220;assign&#8221; operator and the &#8220;comparison: equal&#8221; operator, as opposed to BASIC-languages where both share the same symbol. The other assign operators such as &#8220;+=&#8220;, &#8220;-=&#8220;, &#8220;*=&#8221; and &#8220;\/=&#8220;, in comparison, operate the same way in both languages &#8211; almost. In C-languages you can use assign operators pretty [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[5,8],"_links":{"self":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts\/67"}],"collection":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/comments?post=67"}],"version-history":[{"count":0,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts\/67\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/media?parent=67"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/categories?post=67"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/tags?post=67"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}