Page 1 of 1

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

Posted: Mon Mar 07, 2022 7:49 pm
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