Message Boards Message Boards

0
|
6546 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[?] Declare a local variable?

Posted 7 years ago

Hi guys

I would like to declare location variable so it will not be signed on the global here is a simple code ( as image attach)

thank youenter image description here

POSTED BY: Sheng Dai
2 Replies

You can localize a variable with Module:

local[parameter_] := Module[{localVariable},
  localVariable = parameter*2;
  Return[localVariable]]

No need for Return. In your special case you can achieve the same output with simpler inputs:

local[parameter_] := Module[{localVariable},
  localVariable = parameter*2;
  localVariable]
local[parameter_] := Module[{localVariable},
  localVariable = parameter*2]
local[parameter_] := parameter*2
POSTED BY: Gianluca Gorni

See Module and friends. More in:

https://mathematica.stackexchange.com/q/559/5478

POSTED BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract