Stage 97: Shortcut Operators :+, :-, :*, :/

Follow the development of the SharpBASIC compiler and share your thoughts and ideas.
Locked
User avatar
frank
Site Admin
Posts: 40
Joined: Sun Nov 21, 2021 12:04 pm
Location: Netherlands
Contact:

Stage 97: Shortcut Operators :+, :-, :*, :/

Post by frank »

Next to the increment (:++) and decrement (:--) operators (see stage 96), SharpBASIC supports the 'shortcut' assignment operators :+ (addition), :- (subtraction), :* (multiplication) and :/ (division).

Example:

Code: Select all

dim a:int=5;

main do
  a:+5;         ' equivalent to "a = a + 5;"
  print(a);     ' 10
  a:-3;         ' equivalent to "a = a - 3;"
  print(a);     ' 7
  a:*7;         ' equivalent to "a = a * 7;"
  print(a);     ' 49
  a:++;         ' equivalent to less optimal "a:+1" and "a = a + 1;"
  print(a);     ' 50
  a:/10;        ' equivalent to "a = a / 10;"
  print(a);     ' 5
end
Last edited by frank on Wed Mar 09, 2022 10:54 pm, edited 1 time in total.
Keep it simple!
Locked