Summary of how to write increment / decrement (Scala, Java, Rust, C, C ++, Go, PHP, Perl, Python, Ruby, JavaScript)

If you touch various languages, the detailed specifications of the language will gradually become messed up, so this is a memo.

With or without increment decrement

Yes: Java, C, C ++, Go △, PHP, Perl, JavaScript None: Scala, Rust, Python, Ruby

By treating the Go language as a statement rather than an operator that composes an expression, it avoids the problem of an increment operator, and I personally feel that it is just the right specification.

I also checked the assignment operator, but it seems to be in most languages.

Scala

--No increment / decrement operator --There is an assignment operator

i += 1
i -= 1

ʻI + = 1 etc. is syntactic sugar such as ʻi = i + 1.

reference

Assignment Operators - Expressions | Scala 2.13

Why can't I increment or decrement in Scala?

Java

--Increment / decrement operators have both prefixes and suffixes --Expression and returns a value --There is also an assignment operator

++i;
--i;
i++;
i--;
i += 1;
i -= 1;

reference

Prefix Increment Operator ++ - Java Language Specification

Rust

--No increment / decrement operator --There is an assignment operator

i += 1;
i -= 1;

reference

Compound assignment expressions - Operator expressions - The Rust Reference

Why is there no increment operator? Why doesn't Rust have increment and decrement operators?

C language, C ++

--Increment / decrement operators have both prefixes and suffixes --Expression and returns a value --There is also an assignment operator

++i;
--i;
i++;
i--;
i += 1;
i -= 1;

Go language

--Increment / decrement operator in C language is only postfix --Since it is treated as a statement, not an expression, it cannot be embedded in an expression. --There is also an assignment operator

i++
i--
i += 1
i -= 1

reference

IncDec statements - The Go Programming Language Specification

The case where ++ and -- are not operators Operators and Statements — Programming Language Go | text.Baldanders.info

PHP

--Increment / decrement operators have both prefixes and suffixes --Expression and returns a value --There is also an assignment operator

++$i;
--$i;
$i++;
$i--;
$i += 1;
$i -= 1;

reference

Adder / Subtractor | PHP Manual

Perl

--Increment / decrement operators have both prefixes and suffixes --Expression and returns a value --There is also an assignment operator

++$i;
--$i;
$i++;
$i--;
$i += 1;
$i -= 1;

reference

Increment and decrement --perlop --Perl operators and precedence --perldoc.jp

Python

--No increment / decrement operator --There is an assignment operator

i += 1
i -= 1

It seems to be a cumulative assignment statement.

reference

Augmented assignment statement-simple statement — Python 3.8.0 documentation

Ruby

--No increment / decrement operator --There is an assignment operator

i += 1
i -= 1

It seems to be self-assignment.

reference

Operator expression (Ruby 2.6.0)

Why there is no such thing as an increment operator in Ruby --fugafuga.write

Comparison of Ruby increment speed by version --Qiita

JavaScript

--Increment / decrement operators have both prefixes and suffixes --Expression and returns a value --There is also an assignment operator

++i;
--i;
i++;
i--;
i += 1;
i -= 1;

reference

Update Expressions - ECMAScript® 2019 Language Specification

Recommended Posts

Summary of how to write increment / decrement (Scala, Java, Rust, C, C ++, Go, PHP, Perl, Python, Ruby, JavaScript)
Summary of how to write if statements (Scala, Java, Rust, C language, C ++, Go language, PHP, Perl, Python, Ruby)
Behavior of division operators between integers (C, C ++, Scala, Java, Rust, Go, PHP, JavaScript, Perl, Python, Ruby)
Let's write Python, Ruby, PHP, Java, JavaScript side respectively
How to handle JSON in Ruby, Python, JavaScript, PHP
Let's see how to count the number of elements in an array in some languages [Go, JavaScript, PHP, Python, Ruby, Swift]
[Python] Summary of how to use pandas
[Python2.7] Summary of how to use unittest
Summary of how to use Python list
[Python2.7] Summary of how to use subprocess
How to write Ruby to_s in Python
Summary of how to write AWS Lambda
How to write the correct shebang in Perl, Python and Ruby scripts
Summary of how to import files in Python 3
Summary of how to use MNIST in Python
[Python] Summary of eval / exec functions + How to write character strings with line breaks
From the initial state of CentOS8 to running php python perl ruby with nginx
2014 Web Application Framework Trends (PHP / Java / Ruby / Python / Perl)
How to write a list / dictionary type of Python3
[Python] Summary of how to specify the color of the figure
python, php, ruby How to convert decimal numbers to n-ary numbers
[python] Summary of how to retrieve lists and dictionary elements
[Linux] [C / C ++] Summary of how to get pid, ppid, tid
[Python] Summary of how to use split and join functions
Summary of how to write .proto files used in gRPC
Hello World in various languages [Python / PHP / Java / Perl / Ruby]
About Perl, Python, PHP, Ruby
Offline real-time how to write E11 ruby and python implementation example
Offline real-time how to write Python implementation example of E15 problem
Difference in how to write if statement between ruby ​​and python
Solving with Ruby, Perl, Java, and Python AtCoder ABC 065 C factorial
How to write a Python class
Multi-stage selection (Go / C # / Ruby / Python)
Summary of how to use pandas.DataFrame.loc
How to wrap C in Python
Summary of how to use csvkit
[Scraping Summary] | Python Node.js PHP Ruby Go VBA | Scraping Yahoo! Top in 6 languages
Solving with Ruby, Perl, Java, and Python AtCoder ARC 098 C Cumulative sum
Solving with Ruby, Perl, Java and Python AtCoder CADDi 2018 C Prime Factorization
Solve with Ruby, Perl, Java and Python AtCoder ABC 047 C Regular Expression
Summary of how to set up major Python Lint (pep8, pylint, flake8)