Simple short expressions in RPG

  • Home
  • /
  • Blog
  • /
  • Simple short expressions in RPG

October 1, 2021

Short expressions – simple math expressions (+ = …)

: Is A=A+1 the same as A += 1 ?

The short answer is YES

If you are an old style RPG programmer, evolving into a modern RPG programmer you will frequently see this style of coding when looking at modern RPGLE code examples:

  • $variable += 1;
  • $variable -= 1;
  • $variable *= 2;
  • $variable /= 2;

This math notation simply means “take the right side and apply it to the left side of the value”

So – $variable += 1 could also be written at $variable = $variable + 1

Or we could negate a value by typing $variable *= -1

I like it and have used this style for years.

Try it!


But remember, don’t mix up up += with =+

  • $variable += 1 will add one to the value $variable
  • $variable =+ 1 will set the value of $variable to ‘+1’

😉

NickLitten


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad and Passionate Eater of Cheese and Biscuits.

Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day.

Enjoy your stay, feel free to comment and remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

  • “NOTE – dont mix up up += with =+”

    that is enough reason for me to never use this style of coding

    at least with $variable = $variable +1, there is no confusion.

    • Used Like in other Languages, there is no confusion, if you are not confused. Thats the best improvement ever.
      If you still hold on old writing styles, you probably coding fixed format ?

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Subscribe NOW
    7-day free trial

    Take This Course with ALL ACCESS

    Unlock your Learning Potential with instant access to every course and all new courses as they are released.
     [ For Serious Software Developers only ]

    Online Learning for IBM i Software Technology Professionals

    “The more that you read, the more things you will know. The more that you learn, the more places you’ll go.” – Dr. Seuss

    >