4 Replies - 5769 Views - Last Post: 16 March 2010 - 06:13 PM

#1 Electric_Embers  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 20-February 09

Can you assign multiple variables at once?

Posted 16 March 2010 - 03:43 PM

Is it possible to assign multiple variables at once? For example:

var int1,int2,int3,int4,int5 = 0

I'm just wondering because I did this without thinking and my program never gave me an error and everything worked fine. Is it because these variables are set to 0 by default or what? If it does work, are there any other languages that this works in such as vbscript?
Is This A Good Question/Topic? 0
  • +

Replies To: Can you assign multiple variables at once?

#2 Electric_Embers  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 20-February 09

Re: Can you assign multiple variables at once?

Posted 16 March 2010 - 03:45 PM

Also, is it possible to assign multiple variables at once such as:

var1, var2, var3 = 0
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1633
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Can you assign multiple variables at once?

Posted 16 March 2010 - 05:30 PM

Topics merged. Please do not ask the same question multiple times :)
Was This Post Helpful? 0
  • +
  • -

#4 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1105
  • View blog
  • Posts: 6,918
  • Joined: 07-September 06

Re: Can you assign multiple variables at once?

Posted 16 March 2010 - 06:11 PM

Yes, but the syntax is a little different. It is :
var var1 = var2 = var3 = var4 = 4;



Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10186
  • View blog
  • Posts: 37,611
  • Joined: 27-December 08

Re: Can you assign multiple variables at once?

Posted 16 March 2010 - 06:13 PM

You can also assign multiple variables different values on the same line, like so:
var v1 = 1, v2 = 3, v3 = 4;

//which is the same as
var v1 = 1;
var v2 = 3;
var v3 = 4;


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1