https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Local_variableLocal variable - Revision history2025-06-15T16:36:44ZRevision history for this page on the wikiMediaWiki 1.45.0-wmf.5https://en.wikipedia.org/w/index.php?title=Local_variable&diff=1186802448&oldid=prevMeno25: /* Static local variables */2023-11-25T15:53:43Z<p><span class="autocomment">Static local variables</span></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:53, 25 November 2023</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 10:</td>
<td colspan="2" class="diff-lineno">Line 10:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Static local variables==</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Static local variables==</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>A special type of local variable, called a ''static local,'' is available in many mainstream languages (including [[C (programming language)|C]]/[[C++]], [[Visual Basic]], [[Visual Basic .NET|VB.NET]] and [[PHP]]) which allows a value to be retained from one call of the function to another – it is a [[static variable]] with local scope. In this case, recursive calls to the function also have access to the (single, [[static memory allocation|statically allocated]]) variable. In all of the above languages, static variables are declared as such with a special ''storage class'' keyword (e.g., <code>static</code>).</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>A special type of local variable, called a ''static local,'' is available in many mainstream languages (including [[C (programming language)|C]]/[[C++]], [[Visual Basic]], [[Visual Basic <ins style="font-weight: bold; text-decoration: none;">(</ins>.NET<ins style="font-weight: bold; text-decoration: none;">)</ins>|VB.NET]] and [[PHP]]) which allows a value to be retained from one call of the function to another – it is a [[static variable]] with local scope. In this case, recursive calls to the function also have access to the (single, [[static memory allocation|statically allocated]]) variable. In all of the above languages, static variables are declared as such with a special ''storage class'' keyword (e.g., <code>static</code>).</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Static locals in global functions have the same lifetime as [[static global variable]]s, because their value remains in memory for the life of the program,<ref>{{cite web|url= http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf |title=Current C standard }}&nbsp;{{small|(3.61&nbsp;MB)}} ({{As of|2009|lc=on}}). In particular, see section 6.2.4 “Storage durations of objects”, page 32.</ref> but have [[function scope]] (not global scope), as with automatic local variables.</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Static locals in global functions have the same lifetime as [[static global variable]]s, because their value remains in memory for the life of the program,<ref>{{cite web|url= http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf |title=Current C standard }}&nbsp;{{small|(3.61&nbsp;MB)}} ({{As of|2009|lc=on}}). In particular, see section 6.2.4 “Storage durations of objects”, page 32.</ref> but have [[function scope]] (not global scope), as with automatic local variables.</div></td>
</tr>
</table>Meno25https://en.wikipedia.org/w/index.php?title=Local_variable&diff=1186791463&oldid=prevMeno25: /* Local variables in Perl */2023-11-25T14:14:39Z<p><span class="autocomment">Local variables in Perl</span></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 14:14, 25 November 2023</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 18:</td>
<td colspan="2" class="diff-lineno">Line 18:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Local variables in Perl==</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Local variables in Perl==</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[[Perl]] supports both dynamic and lexically-scoped local variables. The keyword <code>local</code> is used to define local dynamically-scoped variables, while <code>my</code> is used for local lexically-scoped variables. Since dynamic scoping is less common today, the Perl documentation warns that "<code>local</code> isn't what most people think of as “local”.".<ref>[http://perldoc.perl.org/functions/local.html perldoc.perl.org: local]</ref> Instead, the <code>local</code> keyword gives a temporary, [[scope (<del style="font-weight: bold; text-decoration: none;">programming</del>)|dynamically-scoped]] value to a global (package) variable, which lasts until the end of the enclosing block. However, the variable is visible to any function called from within the block.<ref>[http://perldoc.perl.org/perlsub.html#Temporary-Values-via-local() perldoc.perl.org: perlsub: Temporary Values via <code>local()</code>]</ref> To create lexically-scoped local variables, use the <code>my</code> operator instead.<ref>[http://perldoc.perl.org/perlsub.html#Private-Variables-via-my() perldoc.perl.org: perlsub: Private Variables via <code>my()</code>]</ref></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[Perl]] supports both dynamic and lexically-scoped local variables. The keyword <code>local</code> is used to define local dynamically-scoped variables, while <code>my</code> is used for local lexically-scoped variables. Since dynamic scoping is less common today, the Perl documentation warns that "<code>local</code> isn't what most people think of as “local”.".<ref>[http://perldoc.perl.org/functions/local.html perldoc.perl.org: local]</ref> Instead, the <code>local</code> keyword gives a temporary, [[scope (<ins style="font-weight: bold; text-decoration: none;">computer science</ins>)|dynamically-scoped]] value to a global (package) variable, which lasts until the end of the enclosing block. However, the variable is visible to any function called from within the block.<ref>[http://perldoc.perl.org/perlsub.html#Temporary-Values-via-local() perldoc.perl.org: perlsub: Temporary Values via <code>local()</code>]</ref> To create lexically-scoped local variables, use the <code>my</code> operator instead.<ref>[http://perldoc.perl.org/perlsub.html#Private-Variables-via-my() perldoc.perl.org: perlsub: Private Variables via <code>my()</code>]</ref></div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>To understand how it works consider the following code:</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>To understand how it works consider the following code:</div></td>
</tr>
</table>Meno25https://en.wikipedia.org/w/index.php?title=Local_variable&diff=1182819931&oldid=prevShadow311: Reverted edits by 104.244.105.109 (talk) (AV)2023-10-31T15:43:39Z<p>Reverted edits by <a href="/wiki/Special:Contributions/104.244.105.109" title="Special:Contributions/104.244.105.109">104.244.105.109</a> (<a href="/wiki/User_talk:104.244.105.109" title="User talk:104.244.105.109">talk</a>) (<a href="/wiki/Wikipedia:AntiVandal" title="Wikipedia:AntiVandal">AV</a>)</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:43, 31 October 2023</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>{{Short description|Computer programming, a variable<del style="font-weight: bold; text-decoration: none;"> not</del> only<del style="font-weight: bold; text-decoration: none;"> not</del> usable in a portion of a program (the scope)}}</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>{{Short description|Computer programming, a variable only usable in a portion of a program (the scope)}}</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In [[computer science]], a '''local variable''' is a [[Variable (programming)|variable]] that is given ''local [[scope (programming)|scope]]''. A local variable reference in the [[subroutine|function]] or [[block (programming)|block]] in which it is declared overrides the same variable name in the larger scope. In [[programming language]]s with only two levels of visibility, local variables are contrasted with [[global variables]]. On the other hand, many [[ALGOL]]-derived languages allow any number of nested levels of visibility, with private variables, functions, constants and types hidden within them, either by nested blocks or [[nested function]]s. Local variables are fundamental to [[procedural programming]], and more generally [[modular programming]]: variables of local scope are used to avoid issues with [[side-effect (computer science)|side-effects]] that can occur with [[global variable]]s.</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In [[computer science]], a '''local variable''' is a [[Variable (programming)|variable]] that is given ''local [[scope (programming)|scope]]''. A local variable reference in the [[subroutine|function]] or [[block (programming)|block]] in which it is declared overrides the same variable name in the larger scope. In [[programming language]]s with only two levels of visibility, local variables are contrasted with [[global variables]]. On the other hand, many [[ALGOL]]-derived languages allow any number of nested levels of visibility, with private variables, functions, constants and types hidden within them, either by nested blocks or [[nested function]]s. Local variables are fundamental to [[procedural programming]], and more generally [[modular programming]]: variables of local scope are used to avoid issues with [[side-effect (computer science)|side-effects]] that can occur with [[global variable]]s.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Scope==</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Scope==</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>Local variables <del style="font-weight: bold; text-decoration: none;">will not</del> have a lexical or dynamic [[scope (programming)|scope]], though lexical (static) scoping is far more common. In lexical scoping (or lexical scope; also called static scoping or static scope), if a variable <del style="font-weight: bold; text-decoration: none;">generic names</del>'s scope is a certain block, then its scope is the program text of the block definition: within that block's text, the variable name exists, and is bound to the variable's value, but outside that block's text, the variable name does not exist. By contrast, in dynamic scoping (or dynamic scope), if a variable name's scope is a certain block, then its scope is that block and all functions transitively called by that block (except when overridden again by another declaration); after the block ends, the variable name does not exist. Some languages, like [[Perl]] and [[Common Lisp]], allow the programmer to choose static or dynamic scoping when defining or redefining a variable. Examples of languages that use dynamic scoping include [[Logo (programming language)|Logo]], [[Emacs lisp]], and the shell languages [[Bash (Unix shell)|bash]], [[dash (shell)|dash]], and the <del style="font-weight: bold; text-decoration: none;">MirBSC</del> Korn<del style="font-weight: bold; text-decoration: none;"> upper</del> shell ([[mksh]])'s "<del style="font-weight: bold; text-decoration: none;">recent</del>" declaration. Most other languages provide lexically scoped local variables.</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Local variables <ins style="font-weight: bold; text-decoration: none;">may</ins> have a lexical or dynamic [[scope (programming)|scope]], though lexical (static) scoping is far more common. In lexical scoping (or lexical scope; also called static scoping or static scope), if a variable <ins style="font-weight: bold; text-decoration: none;">name</ins>'s scope is a certain block, then its scope is the program text of the block definition: within that block's text, the variable name exists, and is bound to the variable's value, but outside that block's text, the variable name does not exist. By contrast, in dynamic scoping (or dynamic scope), if a variable name's scope is a certain block, then its scope is that block and all functions transitively called by that block (except when overridden again by another declaration); after the block ends, the variable name does not exist. Some languages, like [[Perl]] and [[Common Lisp]], allow the programmer to choose static or dynamic scoping when defining or redefining a variable. Examples of languages that use dynamic scoping include [[Logo (programming language)|Logo]], [[Emacs lisp]], and the shell languages [[Bash (Unix shell)|bash]], [[dash (shell)|dash]], and the <ins style="font-weight: bold; text-decoration: none;">MirBSD</ins> Korn shell ([[mksh]])'s "<ins style="font-weight: bold; text-decoration: none;">local</ins>" declaration. Most other languages provide lexically scoped local variables.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In most languages, local variables are [[automatic variable]]s stored on the [[call stack]] directly. This means that when a [[recursion (computer science)|recursive function]] calls itself, local variables in each instance of the function are given distinct [[Memory address|addresses]]. Hence variables of this scope can be declared, written to, and read, without any risk of [[side-effect (computer science)|side-effects]] to functions outside of the block in which they are declared.</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In most languages, local variables are [[automatic variable]]s stored on the [[call stack]] directly. This means that when a [[recursion (computer science)|recursive function]] calls itself, local variables in each instance of the function are given distinct [[Memory address|addresses]]. Hence variables of this scope can be declared, written to, and read, without any risk of [[side-effect (computer science)|side-effects]] to functions outside of the block in which they are declared.</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 18:</td>
<td colspan="2" class="diff-lineno">Line 18:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Local variables in Perl==</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Local variables in Perl==</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[[Perl]] supports both dynamic and lexically-scoped local variables. The keyword <code>local</code> is used to define local dynamically-scoped variables, while <code>my</code> is used for local lexically-scoped variables. Since dynamic scoping is less common today, the Perl documentation warns that "<code>local</code> isn't what most people think of as “local”.".<ref>[http://perldoc.perl.org/functions/local.html perldoc.perl.org: local]</ref> Instead<del style="font-weight: bold; text-decoration: none;"> ur fat</del>, the <code>local</code> keyword gives a temporary, [[scope (programming)|dynamically-scoped]] value to a global (package) variable, which lasts until the end of the enclosing block. However, the variable is visible to any function called from within the block.<ref>[http://perldoc.perl.org/perlsub.html#Temporary-Values-via-local() perldoc.perl.org: perlsub: Temporary Values via <code>local()</code>]</ref> To create lexically-scoped local variables, use the <code>my</code> operator instead.<ref>[http://perldoc.perl.org/perlsub.html#Private-Variables-via-my() perldoc.perl.org: perlsub: Private Variables via <code>my()</code>]</ref></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[Perl]] supports both dynamic and lexically-scoped local variables. The keyword <code>local</code> is used to define local dynamically-scoped variables, while <code>my</code> is used for local lexically-scoped variables. Since dynamic scoping is less common today, the Perl documentation warns that "<code>local</code> isn't what most people think of as “local”.".<ref>[http://perldoc.perl.org/functions/local.html perldoc.perl.org: local]</ref> Instead, the <code>local</code> keyword gives a temporary, [[scope (programming)|dynamically-scoped]] value to a global (package) variable, which lasts until the end of the enclosing block. However, the variable is visible to any function called from within the block.<ref>[http://perldoc.perl.org/perlsub.html#Temporary-Values-via-local() perldoc.perl.org: perlsub: Temporary Values via <code>local()</code>]</ref> To create lexically-scoped local variables, use the <code>my</code> operator instead.<ref>[http://perldoc.perl.org/perlsub.html#Private-Variables-via-my() perldoc.perl.org: perlsub: Private Variables via <code>my()</code>]</ref></div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>To understand how it works consider the following code:</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>To understand how it works consider the following code:</div></td>
</tr>
</table>Shadow311https://en.wikipedia.org/w/index.php?title=Local_variable&diff=1182819906&oldid=prev104.244.105.109 at 15:43, 31 October 20232023-10-31T15:43:27Z<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:43, 31 October 2023</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 18:</td>
<td colspan="2" class="diff-lineno">Line 18:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Local variables in Perl==</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Local variables in Perl==</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[[Perl]] supports both dynamic and lexically-scoped local variables. The keyword <code>local</code> is used to define local dynamically-scoped variables, while <code>my</code> is used for local lexically-scoped variables. Since dynamic scoping is less common today, the Perl documentation warns that "<code>local</code> isn't what most people think of as “local”.".<ref>[http://perldoc.perl.org/functions/local.html perldoc.perl.org: local]</ref> Instead, the <code>local</code> keyword gives a temporary, [[scope (programming)|dynamically-scoped]] value to a global (package) variable, which lasts until the end of the enclosing block. However, the variable is visible to any function called from within the block.<ref>[http://perldoc.perl.org/perlsub.html#Temporary-Values-via-local() perldoc.perl.org: perlsub: Temporary Values via <code>local()</code>]</ref> To create lexically-scoped local variables, use the <code>my</code> operator instead.<ref>[http://perldoc.perl.org/perlsub.html#Private-Variables-via-my() perldoc.perl.org: perlsub: Private Variables via <code>my()</code>]</ref></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[Perl]] supports both dynamic and lexically-scoped local variables. The keyword <code>local</code> is used to define local dynamically-scoped variables, while <code>my</code> is used for local lexically-scoped variables. Since dynamic scoping is less common today, the Perl documentation warns that "<code>local</code> isn't what most people think of as “local”.".<ref>[http://perldoc.perl.org/functions/local.html perldoc.perl.org: local]</ref> Instead<ins style="font-weight: bold; text-decoration: none;"> ur fat</ins>, the <code>local</code> keyword gives a temporary, [[scope (programming)|dynamically-scoped]] value to a global (package) variable, which lasts until the end of the enclosing block. However, the variable is visible to any function called from within the block.<ref>[http://perldoc.perl.org/perlsub.html#Temporary-Values-via-local() perldoc.perl.org: perlsub: Temporary Values via <code>local()</code>]</ref> To create lexically-scoped local variables, use the <code>my</code> operator instead.<ref>[http://perldoc.perl.org/perlsub.html#Private-Variables-via-my() perldoc.perl.org: perlsub: Private Variables via <code>my()</code>]</ref></div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>To understand how it works consider the following code:</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>To understand how it works consider the following code:</div></td>
</tr>
</table>104.244.105.109https://en.wikipedia.org/w/index.php?title=Local_variable&diff=1182819826&oldid=prev104.244.105.109 at 15:42, 31 October 20232023-10-31T15:42:52Z<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:42, 31 October 2023</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>{{Short description|Computer programming, a variable only usable in a portion of a program (the scope)}}</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>{{Short description|Computer programming, a variable<ins style="font-weight: bold; text-decoration: none;"> not</ins> only<ins style="font-weight: bold; text-decoration: none;"> not</ins> usable in a portion of a program (the scope)}}</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In [[computer science]], a '''local variable''' is a [[Variable (programming)|variable]] that is given ''local [[scope (programming)|scope]]''. A local variable reference in the [[subroutine|function]] or [[block (programming)|block]] in which it is declared overrides the same variable name in the larger scope. In [[programming language]]s with only two levels of visibility, local variables are contrasted with [[global variables]]. On the other hand, many [[ALGOL]]-derived languages allow any number of nested levels of visibility, with private variables, functions, constants and types hidden within them, either by nested blocks or [[nested function]]s. Local variables are fundamental to [[procedural programming]], and more generally [[modular programming]]: variables of local scope are used to avoid issues with [[side-effect (computer science)|side-effects]] that can occur with [[global variable]]s.</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In [[computer science]], a '''local variable''' is a [[Variable (programming)|variable]] that is given ''local [[scope (programming)|scope]]''. A local variable reference in the [[subroutine|function]] or [[block (programming)|block]] in which it is declared overrides the same variable name in the larger scope. In [[programming language]]s with only two levels of visibility, local variables are contrasted with [[global variables]]. On the other hand, many [[ALGOL]]-derived languages allow any number of nested levels of visibility, with private variables, functions, constants and types hidden within them, either by nested blocks or [[nested function]]s. Local variables are fundamental to [[procedural programming]], and more generally [[modular programming]]: variables of local scope are used to avoid issues with [[side-effect (computer science)|side-effects]] that can occur with [[global variable]]s.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Scope==</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Scope==</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>Local variables <del style="font-weight: bold; text-decoration: none;">may</del> have a lexical or dynamic [[scope (programming)|scope]], though lexical (static) scoping is far more common. In lexical scoping (or lexical scope; also called static scoping or static scope), if a variable <del style="font-weight: bold; text-decoration: none;">name</del>'s scope is a certain block, then its scope is the program text of the block definition: within that block's text, the variable name exists, and is bound to the variable's value, but outside that block's text, the variable name does not exist. By contrast, in dynamic scoping (or dynamic scope), if a variable name's scope is a certain block, then its scope is that block and all functions transitively called by that block (except when overridden again by another declaration); after the block ends, the variable name does not exist. Some languages, like [[Perl]] and [[Common Lisp]], allow the programmer to choose static or dynamic scoping when defining or redefining a variable. Examples of languages that use dynamic scoping include [[Logo (programming language)|Logo]], [[Emacs lisp]], and the shell languages [[Bash (Unix shell)|bash]], [[dash (shell)|dash]], and the <del style="font-weight: bold; text-decoration: none;">MirBSD</del> Korn shell ([[mksh]])'s "<del style="font-weight: bold; text-decoration: none;">local</del>" declaration. Most other languages provide lexically scoped local variables.</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Local variables <ins style="font-weight: bold; text-decoration: none;">will not</ins> have a lexical or dynamic [[scope (programming)|scope]], though lexical (static) scoping is far more common. In lexical scoping (or lexical scope; also called static scoping or static scope), if a variable <ins style="font-weight: bold; text-decoration: none;">generic names</ins>'s scope is a certain block, then its scope is the program text of the block definition: within that block's text, the variable name exists, and is bound to the variable's value, but outside that block's text, the variable name does not exist. By contrast, in dynamic scoping (or dynamic scope), if a variable name's scope is a certain block, then its scope is that block and all functions transitively called by that block (except when overridden again by another declaration); after the block ends, the variable name does not exist. Some languages, like [[Perl]] and [[Common Lisp]], allow the programmer to choose static or dynamic scoping when defining or redefining a variable. Examples of languages that use dynamic scoping include [[Logo (programming language)|Logo]], [[Emacs lisp]], and the shell languages [[Bash (Unix shell)|bash]], [[dash (shell)|dash]], and the <ins style="font-weight: bold; text-decoration: none;">MirBSC</ins> Korn<ins style="font-weight: bold; text-decoration: none;"> upper</ins> shell ([[mksh]])'s "<ins style="font-weight: bold; text-decoration: none;">recent</ins>" declaration. Most other languages provide lexically scoped local variables.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In most languages, local variables are [[automatic variable]]s stored on the [[call stack]] directly. This means that when a [[recursion (computer science)|recursive function]] calls itself, local variables in each instance of the function are given distinct [[Memory address|addresses]]. Hence variables of this scope can be declared, written to, and read, without any risk of [[side-effect (computer science)|side-effects]] to functions outside of the block in which they are declared.</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In most languages, local variables are [[automatic variable]]s stored on the [[call stack]] directly. This means that when a [[recursion (computer science)|recursive function]] calls itself, local variables in each instance of the function are given distinct [[Memory address|addresses]]. Hence variables of this scope can be declared, written to, and read, without any risk of [[side-effect (computer science)|side-effects]] to functions outside of the block in which they are declared.</div></td>
</tr>
</table>104.244.105.109https://en.wikipedia.org/w/index.php?title=Local_variable&diff=1164695390&oldid=prev82.18.7.139: /* Static local variables */2023-07-10T14:52:49Z<p><span class="autocomment">Static local variables</span></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 14:52, 10 July 2023</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 10:</td>
<td colspan="2" class="diff-lineno">Line 10:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Static local variables==</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Static local variables==</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>A special type of local variable, called a ''static local,'' is available in many mainstream languages (including [[C (programming language)|C]]/[[C++]], [[Visual Basic]],<del style="font-weight: bold; text-decoration: none;"> and</del> [[Visual Basic .NET|VB.NET]]) which allows a value to be retained from one call of the function to another – it is a [[static variable]] with local scope. In this case, recursive calls to the function also have access to the (single, [[static memory allocation|statically allocated]]) variable. In all of the above languages, static variables are declared as such with a special ''storage class'' keyword (e.g., <code>static</code>).</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>A special type of local variable, called a ''static local,'' is available in many mainstream languages (including [[C (programming language)|C]]/[[C++]], [[Visual Basic]], [[Visual Basic .NET|VB.NET<ins style="font-weight: bold; text-decoration: none;">]] and [[PHP</ins>]]) which allows a value to be retained from one call of the function to another – it is a [[static variable]] with local scope. In this case, recursive calls to the function also have access to the (single, [[static memory allocation|statically allocated]]) variable. In all of the above languages, static variables are declared as such with a special ''storage class'' keyword (e.g., <code>static</code>).</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Static locals in global functions have the same lifetime as [[static global variable]]s, because their value remains in memory for the life of the program,<ref>{{cite web|url= http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf |title=Current C standard }}&nbsp;{{small|(3.61&nbsp;MB)}} ({{As of|2009|lc=on}}). In particular, see section 6.2.4 “Storage durations of objects”, page 32.</ref> but have [[function scope]] (not global scope), as with automatic local variables.</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Static locals in global functions have the same lifetime as [[static global variable]]s, because their value remains in memory for the life of the program,<ref>{{cite web|url= http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf |title=Current C standard }}&nbsp;{{small|(3.61&nbsp;MB)}} ({{As of|2009|lc=on}}). In particular, see section 6.2.4 “Storage durations of objects”, page 32.</ref> but have [[function scope]] (not global scope), as with automatic local variables.</div></td>
</tr>
</table>82.18.7.139https://en.wikipedia.org/w/index.php?title=Local_variable&diff=1098393930&oldid=prevOrandlogic at 16:38, 15 July 20222022-07-15T16:38:36Z<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 16:38, 15 July 2022</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{Short description|Computer programming, a variable only usable in a portion of a program (the scope)}}</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{Short description|Computer programming, a variable only usable in a portion of a program (the scope)}}</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>In [[computer science]], a '''local variable''' is a [[Variable (programming)|variable]] that is given ''local [[scope (programming)|scope]]''. <del style="font-weight: bold; text-decoration: none;">Local</del> variable <del style="font-weight: bold; text-decoration: none;">references</del> in the [[subroutine|function]] or [[block (programming)|block]] in which it is declared <del style="font-weight: bold; text-decoration: none;">override</del> the same variable name in the larger scope. In [[programming language]]s with only two levels of visibility, local variables are contrasted with [[global variables]]. On the other hand, many [[ALGOL]]-derived languages allow any number of nested levels of visibility, with private variables, functions, constants and types hidden within them, either by nested blocks or [[nested function]]s. Local variables are fundamental to [[procedural programming]], and more generally [[modular programming]]: variables of local scope are used to avoid issues with [[side-effect (computer science)|side-effects]] that can occur with [[global variable]]s.</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>In [[computer science]], a '''local variable''' is a [[Variable (programming)|variable]] that is given ''local [[scope (programming)|scope]]''. <ins style="font-weight: bold; text-decoration: none;">A local</ins> variable <ins style="font-weight: bold; text-decoration: none;">reference</ins> in the [[subroutine|function]] or [[block (programming)|block]] in which it is declared <ins style="font-weight: bold; text-decoration: none;">overrides</ins> the same variable name in the larger scope. In [[programming language]]s with only two levels of visibility, local variables are contrasted with [[global variables]]. On the other hand, many [[ALGOL]]-derived languages allow any number of nested levels of visibility, with private variables, functions, constants and types hidden within them, either by nested blocks or [[nested function]]s. Local variables are fundamental to [[procedural programming]], and more generally [[modular programming]]: variables of local scope are used to avoid issues with [[side-effect (computer science)|side-effects]] that can occur with [[global variable]]s.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Scope==</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==Scope==</div></td>
</tr>
</table>Orandlogichttps://en.wikipedia.org/w/index.php?title=Local_variable&diff=1020957262&oldid=prevCannedCans: Adding short description: "Computer programming, a variable only usable in a portion of a program (the scope)" (Shortdesc helper)2021-05-02T02:10:04Z<p>Adding <a href="/wiki/Wikipedia:Short_description" title="Wikipedia:Short description">short description</a>: "Computer programming, a variable only usable in a portion of a program (the scope)" (<a href="/wiki/Wikipedia:Shortdesc_helper" title="Wikipedia:Shortdesc helper">Shortdesc helper</a>)</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 02:10, 2 May 2021</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>{{Short description|Computer programming, a variable only usable in a portion of a program (the scope)}}</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In [[computer science]], a '''local variable''' is a [[Variable (programming)|variable]] that is given ''local [[scope (programming)|scope]]''. Local variable references in the [[subroutine|function]] or [[block (programming)|block]] in which it is declared override the same variable name in the larger scope. In [[programming language]]s with only two levels of visibility, local variables are contrasted with [[global variables]]. On the other hand, many [[ALGOL]]-derived languages allow any number of nested levels of visibility, with private variables, functions, constants and types hidden within them, either by nested blocks or [[nested function]]s. Local variables are fundamental to [[procedural programming]], and more generally [[modular programming]]: variables of local scope are used to avoid issues with [[side-effect (computer science)|side-effects]] that can occur with [[global variable]]s.</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In [[computer science]], a '''local variable''' is a [[Variable (programming)|variable]] that is given ''local [[scope (programming)|scope]]''. Local variable references in the [[subroutine|function]] or [[block (programming)|block]] in which it is declared override the same variable name in the larger scope. In [[programming language]]s with only two levels of visibility, local variables are contrasted with [[global variables]]. On the other hand, many [[ALGOL]]-derived languages allow any number of nested levels of visibility, with private variables, functions, constants and types hidden within them, either by nested blocks or [[nested function]]s. Local variables are fundamental to [[procedural programming]], and more generally [[modular programming]]: variables of local scope are used to avoid issues with [[side-effect (computer science)|side-effects]] that can occur with [[global variable]]s.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
</table>CannedCanshttps://en.wikipedia.org/w/index.php?title=Local_variable&diff=1018299007&oldid=prevLocal Variable: Add heading to make the lead more concise - per MOS:INTRO2021-04-17T09:09:14Z<p>Add heading to make the lead more concise - per <a href="/wiki/MOS:INTRO" class="mw-redirect" title="MOS:INTRO">MOS:INTRO</a></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 09:09, 17 April 2021</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In [[computer science]], a '''local variable''' is a [[Variable (programming)|variable]] that is given ''local [[scope (programming)|scope]]''. Local variable references in the [[subroutine|function]] or [[block (programming)|block]] in which it is declared override the same variable name in the larger scope. In [[programming language]]s with only two levels of visibility, local variables are contrasted with [[global variables]]. On the other hand, many [[ALGOL]]-derived languages allow any number of nested levels of visibility, with private variables, functions, constants and types hidden within them, either by nested blocks or [[nested function]]s. Local variables are fundamental to [[procedural programming]], and more generally [[modular programming]]: variables of local scope are used to avoid issues with [[side-effect (computer science)|side-effects]] that can occur with [[global variable]]s.</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>In [[computer science]], a '''local variable''' is a [[Variable (programming)|variable]] that is given ''local [[scope (programming)|scope]]''. Local variable references in the [[subroutine|function]] or [[block (programming)|block]] in which it is declared override the same variable name in the larger scope. In [[programming language]]s with only two levels of visibility, local variables are contrasted with [[global variables]]. On the other hand, many [[ALGOL]]-derived languages allow any number of nested levels of visibility, with private variables, functions, constants and types hidden within them, either by nested blocks or [[nested function]]s. Local variables are fundamental to [[procedural programming]], and more generally [[modular programming]]: variables of local scope are used to avoid issues with [[side-effect (computer science)|side-effects]] that can occur with [[global variable]]s.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>==Scope==</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Local variables may have a lexical or dynamic [[scope (programming)|scope]], though lexical (static) scoping is far more common. In lexical scoping (or lexical scope; also called static scoping or static scope), if a variable name's scope is a certain block, then its scope is the program text of the block definition: within that block's text, the variable name exists, and is bound to the variable's value, but outside that block's text, the variable name does not exist. By contrast, in dynamic scoping (or dynamic scope), if a variable name's scope is a certain block, then its scope is that block and all functions transitively called by that block (except when overridden again by another declaration); after the block ends, the variable name does not exist. Some languages, like [[Perl]] and [[Common Lisp]], allow the programmer to choose static or dynamic scoping when defining or redefining a variable. Examples of languages that use dynamic scoping include [[Logo (programming language)|Logo]], [[Emacs lisp]], and the shell languages [[Bash (Unix shell)|bash]], [[dash (shell)|dash]], and the MirBSD Korn shell ([[mksh]])'s "local" declaration. Most other languages provide lexically scoped local variables.</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Local variables may have a lexical or dynamic [[scope (programming)|scope]], though lexical (static) scoping is far more common. In lexical scoping (or lexical scope; also called static scoping or static scope), if a variable name's scope is a certain block, then its scope is the program text of the block definition: within that block's text, the variable name exists, and is bound to the variable's value, but outside that block's text, the variable name does not exist. By contrast, in dynamic scoping (or dynamic scope), if a variable name's scope is a certain block, then its scope is that block and all functions transitively called by that block (except when overridden again by another declaration); after the block ends, the variable name does not exist. Some languages, like [[Perl]] and [[Common Lisp]], allow the programmer to choose static or dynamic scoping when defining or redefining a variable. Examples of languages that use dynamic scoping include [[Logo (programming language)|Logo]], [[Emacs lisp]], and the shell languages [[Bash (Unix shell)|bash]], [[dash (shell)|dash]], and the MirBSD Korn shell ([[mksh]])'s "local" declaration. Most other languages provide lexically scoped local variables.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
</table>Local Variablehttps://en.wikipedia.org/w/index.php?title=Local_variable&diff=956137914&oldid=prevDannyS712 bot: Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags2020-05-11T18:05:20Z<p>Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 18:05, 11 May 2020</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 19:</td>
<td colspan="2" class="diff-lineno">Line 19:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>To understand how it works consider the following code:</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>To understand how it works consider the following code:</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><<del style="font-weight: bold; text-decoration: none;">source</del> lang="perl"></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><<ins style="font-weight: bold; text-decoration: none;">syntaxhighlight</ins> lang="perl"></div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>$a = 1;</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>$a = 1;</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>sub f() {</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>sub f() {</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 32:</td>
<td colspan="2" class="diff-lineno">Line 32:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>f();</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>f();</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>g();</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>g();</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div></syntaxhighlight></div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div></source></div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>this will output:</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>this will output:</div></td>
</tr>
</table>DannyS712 bot