You don’t have to see assigning values to variables as a chore. There are exciting ways to do those assignments - here are some shorthand ways.
Initialize to same value
You can initialize variables like so -
|
|
Or, you can instead do -
|
|
Initialize variables to different values
It is quite common to assign different values during initialization..
|
|
.. so why not have a shorthand for that? Just do assignment using the previous way of combining declarations.
|
|
But, there is also a better way.
|
|
Assign + operate
Do assignments while doing important operations.
Traditional way -
|
|
The cool way -
|
|
Assign in loops
You can assign values when initializing loops.
The traditional way -
|
|
And, the cool way -
|
|