Increment an Integer, a Float, and a Character value.

← Operators and Expressions · Ref: Q1103

Increment and decrement:

  count++
  letter++

Statement-only operators -- cannot be used in expressions. Works on Integer, Float, Character, and other ordered types. See Q967 for increment/decrement rules, Q780 for statement-only restriction.

Example

defines module qa.operators.incrementoperators

  defines program

    IncrementOperatorsDemo()
      stdout <- Stdout()

      //Integer increment
      count <- 10
      count++
      stdout.println(`After ++: ${count}`)
      count--
      stdout.println(`After --: ${count}`)

      //Float increment
      price <- 9.99
      price++
      stdout.println(`Float after ++: ${price}`)

      //Character increment — advances to next code point
      letter <- 'a'
      letter++
      stdout.println(`'a' after ++: ${letter}`)

      //Multiple increments
      digit <- 'A'
      digit++
      digit++
      digit++
      stdout.println(`'A' after +++: ${digit}`)

Common mistakes

E07950 — ++ and -- are statement-only operators in EK9. They cannot be used in expressions or assignments.

Incorrect:

      result <- count++

Correct:

      count++
Other ways to ask this
  • I need to advance a counter, increase a float, and step a character to the next letter
  • In Java I'd use ++ on an int. Show EK9 increment on different types
  • Given an Integer, Float, and Character, apply ++ and -- to each
  • Use the increment and decrement operators across multiple EK9 types

Coming from another language?

Java: count++ (expression). C: count++ (expression). EK9: count++ (statement ONLY — cannot use in expressions like x = count++).

Keywords: increment, ++, Integer, --, Character, Float, decrement