PC Change value of two variables at once

BoliBerrys

C# > Any other language
May 14, 2015
80
47
28
22
Argentina
www.YouTube.com
Hello Guys.

Today i'm going to show you how to make two variables have the same value.

First of, i want to start saying i tested this on JavaScript and on C#. I'm not sure if it works on every language.

Okey. So let's say we have the following variables:

PHP:
int start = 10;
int rounds = 2;
int timer;
int current;
We want timer and current to have the following value:

PHP:
timer = start * rounds;
current = start * rounds;
Instead of typing two times the same line of code, we can do the following:
PHP:
timer = current = start * rounds;
As you can see, it works just fine:
 
  • Like
Reactions: LEGACYY

LEGACYY

⚝ Retired ⚝
RG Prime
Oct 4, 2015
2,355
770
123
Jamaica
Hello Guys.

Today i'm going to show you how to make two variables have the same value.

First of, i want to start saying i tested this on JavaScript and on C#. I'm not sure if it works on every language.

Okey. So let's say we have the following variables:

PHP:
int start = 10;
int rounds = 2;
int timer;
int current;
We want timer and current to have the following value:

PHP:
timer = start * rounds;
current = start * rounds;
Instead of typing two times the same line of code, we can do the following:
PHP:
timer = current = start * rounds;
As you can see, it works just fine:
Great share buddy! :thumbup:
 

1UP

New Gamer
Mar 24, 2015
27
18
13
29
Hello Guys.

Today i'm going to show you how to make two variables have the same value.

First of, i want to start saying i tested this on JavaScript and on C#. I'm not sure if it works on every language.

Okey. So let's say we have the following variables:

PHP:
int start = 10;
int rounds = 2;
int timer;
int current;
We want timer and current to have the following value:

PHP:
timer = start * rounds;
current = start * rounds;
Instead of typing two times the same line of code, we can do the following:
PHP:
timer = current = start * rounds;
As you can see, it works just fine:
While this does work, it's generally bad practice to do something like this especially if you are working on a team project. It actually makes the code harder to read if that makes sense.