<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Arcade: Increment operators (++x and x++) in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-increment-operators-x-and-x/m-p/1151101#M52438</link>
    <description>&lt;P&gt;&lt;BR /&gt;The Arcade developer docs talk about "increment operators":&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;The increment/decrement by one operators have both a pre and post versions that differ in what they return. The pre increment version adds one to the variable and returns the new value while the post increment adds one and then returns the initial value of the variable.&lt;/P&gt;&lt;PRE&gt;//Pre increment example&lt;BR /&gt;var x=10&lt;BR /&gt;++x // x is now 11 and the value 11 is returned&lt;BR /&gt;&lt;BR /&gt;//Post increment example&lt;BR /&gt;var x=10&lt;BR /&gt;x++ // x is now 11 but the value of 10 is returned.&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Question:&lt;BR /&gt;What is an example of using &lt;FONT face="courier new,courier" color="#0000FF"&gt;x++&lt;/FONT&gt; in an Arcade expression? (outside of a for loop)&lt;BR /&gt;I don't think I understand why we'd want to use it: "x is now 11 but the value of 10 is returned".&amp;nbsp; Why would we want to return the&amp;nbsp;"initial value of the variable" (10)?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Related:&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/971312/why-avoid-increment-and-decrement-operators-in-javascript" target="_self"&gt;Why avoid increment ("++") and decrement ("--") operators in JavaScript?&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Sun, 06 Mar 2022 23:22:33 GMT</pubDate>
    <dc:creator>Bud</dc:creator>
    <dc:date>2022-03-06T23:22:33Z</dc:date>
    <item>
      <title>Arcade: Increment operators (++x and x++)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-increment-operators-x-and-x/m-p/1151101#M52438</link>
      <description>&lt;P&gt;&lt;BR /&gt;The Arcade developer docs talk about "increment operators":&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;The increment/decrement by one operators have both a pre and post versions that differ in what they return. The pre increment version adds one to the variable and returns the new value while the post increment adds one and then returns the initial value of the variable.&lt;/P&gt;&lt;PRE&gt;//Pre increment example&lt;BR /&gt;var x=10&lt;BR /&gt;++x // x is now 11 and the value 11 is returned&lt;BR /&gt;&lt;BR /&gt;//Post increment example&lt;BR /&gt;var x=10&lt;BR /&gt;x++ // x is now 11 but the value of 10 is returned.&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Question:&lt;BR /&gt;What is an example of using &lt;FONT face="courier new,courier" color="#0000FF"&gt;x++&lt;/FONT&gt; in an Arcade expression? (outside of a for loop)&lt;BR /&gt;I don't think I understand why we'd want to use it: "x is now 11 but the value of 10 is returned".&amp;nbsp; Why would we want to return the&amp;nbsp;"initial value of the variable" (10)?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Related:&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/971312/why-avoid-increment-and-decrement-operators-in-javascript" target="_self"&gt;Why avoid increment ("++") and decrement ("--") operators in JavaScript?&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 23:22:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-increment-operators-x-and-x/m-p/1151101#M52438</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-03-06T23:22:33Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade: Increment operators (++x and x++)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-increment-operators-x-and-x/m-p/1151168#M52443</link>
      <description>&lt;P&gt;Two basic examples:&lt;/P&gt;&lt;P&gt;Counting&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var interesting_features = 0
for(var f in feature_set) {
    // do something with every feature
    // ...
    // only count interesting features
    if(f.IsInteresting == 1) {
        interesting_features++  // the same as interesting_features += 1
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Legacy Appending&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var arr = []

// Previously, you had to append elements like this
var i = 0
arr[i++] = "a"
arr[i++] = "b"

// Now, you can also do it like this:
Push(arr, "a")
Push(arr, "b")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Why would we want to return the&amp;nbsp;"initial value of the variable"&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;For example, to implement a &lt;A href="https://en.wikipedia.org/wiki/Stack_(abstract_data_type)" target="_blank" rel="noopener"&gt;stack&lt;/A&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var i = 0
var stack = []
function stack_push(val) {stack[i++] = val}
function stack_pop() {return stack[--i]}

stack_push(1)
stack_push(2)
stack_push(3)
Console("stack: " + stack)
Console(stack_pop())
Console(stack_pop())
stack_push("a")
Console("stack: " + stack)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;stack: [1,2,3]
3
2
stack: [1,"a",3]&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Mar 2022 08:37:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-increment-operators-x-and-x/m-p/1151168#M52443</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-03-07T08:37:14Z</dc:date>
    </item>
  </channel>
</rss>

