Change value of two...
 
Notifications
Clear all

Change value of two variables at once


BoliBerrys
Posts: 82
Topic starter
(@BoliBerrys)
Trusted RivalGamer
Joined: 7 years ago

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:

	int start = 10;
	int rounds = 2;
	int timer;
	int current;
	

We want timer and current to have the following value:

	timer = start * rounds;
	current = start * rounds;
	

Instead of typing two times the same line of code, we can do the following:

	timer = current = start * rounds;
	

As you can see, it works just fine:

Reply
2 Replies
LEGACYY
Posts: 2350
(@LEGACYY)
Noble RivalGamer
Joined: 6 years ago

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:

	int start = 10;
	int rounds = 2;
	int timer;
	int current;
	

We want timer and current to have the following value:

	timer = start * rounds;
	current = start * rounds;
	

Instead of typing two times the same line of code, we can do the following:

	timer = current = start * rounds;
	

As you can see, it works just fine:

Great share buddy!

Reply
1UP
Posts: 25
 1UP
(@1UP)
Eminent RivalGamer
Joined: 7 years ago

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:

	int start = 10;
	int rounds = 2;
	int timer;
	int current;
	

We want timer and current to have the following value:

	timer = start * rounds;
	current = start * rounds;
	

Instead of typing two times the same line of code, we can do the following:

	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.

Reply
Menu