• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/tests/custom/01_arithmetic/04_inc_dec

  1 Ucode implements C-style pre- and postfix increment and decrement operators.
  2 
  3 Pre-increment or -decrement operations first mutate the value and then return
  4 the resulting value while post-increment or -decrement operations first return
  5 the initial value and then mutate the operand.
  6 
  7 Since the decrement and increment operators mutate their operand, they
  8 may only be applied to variables, not constant literal expressions.
  9 
 10 If an undefined variable is incremented or decremented, its initial value
 11 is assumed to be "0".
 12 
 13 If a non-numeric value is incremented or decremented, it is converted to a
 14 number first. If the value is not convertible, the result of the increment
 15 or decrement operation is NaN.
 16 
 17 -- Expect stdout --
 18 Incrementing a not existing variable assumes "0" as initial value:
 19 
 20  - Postfix increment result: 0, value after: 1
 21  - Prefix increment result:  1, value after: 1
 22  - Postfix decrement result: 0, value after: -1
 23  - Prefix decrement result:  -1, value after: -1
 24 
 25 Incrementing a non-numeric value will convert it to a number:
 26 
 27 124
 28 3.5
 29 2
 30 NaN
 31 -- End --
 32 
 33 -- Testcase --
 34 Incrementing a not existing variable assumes "0" as initial value:
 35 
 36  - Postfix increment result: {{ "" + a++ }}, value after: {{ a }}
 37  - Prefix increment result:  {{ "" + ++b }}, value after: {{ b }}
 38  - Postfix decrement result: {{ "" + c-- }}, value after: {{ c }}
 39  - Prefix decrement result:  {{ "" + --d }}, value after: {{ d }}
 40 
 41 Incrementing a non-numeric value will convert it to a number:
 42 
 43 {%
 44         n = "123"; n++; print(n, "\n");
 45         n = "4.5"; n--; print(n, "\n");
 46         n = true; n++; print(n, "\n");
 47         n = { some: "object" }; n--; print(n, "\n");
 48 %}
 49 -- End --

This page was automatically generated by LXR 0.3.1.  •  OpenWrt