<doc>
  <legacy_id>3384</legacy_id>
  <name>wrap</name>
  <type>operator</type>
  <syntax>
    <example><i>number</i> wrap <i>divisor</i></example>
  </syntax>
  <library></library>
  <objects>
  </objects>
  <synonyms>
  </synonyms>
  <classification>
  </classification>
  <references>
    <operator tag="/">/ Operator</operator>
  </references>
  <history>
    <introduced version="2.9">Added.</introduced>
  </history>
  <platforms>
    <mac/>
    <windows/>
    <linux/>
    <ios/>
    <android/>
  </platforms>
  <classes>
    <desktop/>
    <server/>
    <web/>
    <mobile/>
  </classes>
  <security>
  </security>
  <summary>Wrap allows the user to ensure the value of a variable stays within a specified range.</summary>
  <examples>
    <example>repeat with x = 1 to 10</p><p>  put item x wrap 3 of "1,2,3" &amp; comma after tOutput</p><p>end repeat</p><p>-- evaluates to 1,2,3,1,2,3,1,2,3,1</p><p/><p>repeat with x=1 to 9</p><p>    put item x wrap 2 of "1,2" &amp; comma after tOutput</p><p>end repeat</p><p>--evaluates to 1,2,1,2,1,2,1,2,1</example>
  </examples>
  <description>
    <p>The wrap function makes it easy to loop successively over a fixed number of items in a list.  When cycling through the items of a list, the divisor parameter specifies which item will cause the cycle to loop back to the beginning of the list. This means that any number outside this range is mapped to a number within it. </p><p/><p>For example, if we had 5 wrap 3, the number 5 would be mapped to the number 2 as this is where the iterator would be pointing on the 5th iteration ie. 1, 2, 3, 1, 2 .  Therefore 5 wrap 3 is 2.</p><p/><p>The mathematical formula implemented by the wrap operator is:</p><p>     x wraps y        =       ((x-1) mod abs(y)) +1 if (x &gt;= 0)</p><p>                             =      -((x-1) mod abs(y)) +1 if(x &lt; 0)</p><p/>
  </description>
</doc>