({{, (RefLink[Block, paclet:ref/Block])[{x,y,…},expr]
specifies that expr is to be evaluated with local values for the symbols x, y, …. }, {, (RefLink[Block, paclet:ref/Block])[{x=(Subscript[x, 0]),…},expr]
defines initial local values for x, …. }})

OpenersNotesSection(Spacer1)Details

(RefLink[Block, paclet:ref/Block]) allows you to set up an environment in which the values of variables can temporarily be changed.

When you execute a block, values assigned to x, y, … are cleared. When the execution of the block is finished, the original values of these symbols are restored.

(RefLink[Block, paclet:ref/Block]) affects only the values of symbols, not their names.

Initial values specified for x, y, … are evaluated before x, y, … are cleared.

You can use (RefLink[Block, paclet:ref/Block])[{vars},body/;cond] as the right-hand side of a transformation rule with a condition attached.

(RefLink[Block, paclet:ref/Block]) has attribute (RefLink[HoldAll, paclet:ref/HoldAll]).

(RefLink[Block, paclet:ref/Block]) implements dynamic scoping of variables.

(RefLink[Block, paclet:ref/Block]) is automatically used to localize values of iterators in iteration constructs such as (RefLink[Do, paclet:ref/Do]), (RefLink[Sum, paclet:ref/Sum]), and (RefLink[Table, paclet:ref/Table]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (7)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Block[{$RecursionLimit=20},x=x+1]

OpenersExampleSection1(Spacer1)Scope  (2)

Temporarily change settings of global system parameters:

Block[{$MaxPrecision=24,$MinPrecision=24},Sin[1`20]]

Block[{$MaxExtraPrecision=100},Sin[Exp[200]]>0]

Evaluate an expression with a variable temporarily set to a given value:

Expand[(1+x)^5]

Block[{x=5},%]

x

OpenersExampleSection2(Spacer1)Applications  (2)

Perform a deeply recursive calculation:

cl[1]=1;
cl[n_Integer?EvenQ]:=cl[n/2]+1
cl[n_Integer?OddQ]:=cl[3n+1]+1

Block[{$RecursionLimit=Infinity},cl[9780657630]]

The default setting of (RefLink[$RecursionLimit, paclet:ref/$RecursionLimit]) is too low for this calculation:

cl[9780657630]

Use a local expression to visualize a complex map:

Block[{f=Sin[x+I y]},ParametricPlot[Evaluate[{Re[f],Im[f]}],{x,-Pi,Pi},{y,-2,2},Mesh->10]]

OpenersExampleSection3(Spacer1)Properties & Relations  (2)

(RefLink[Block, paclet:ref/Block]) localizes values only; it does not create new symbols:

x=7;
Block[{x},Print[x]]

(RefLink[Module, paclet:ref/Module]) creates new symbols:

Module[{x},Print[x]]

Iterators localize their variable in a similar way to (RefLink[Block, paclet:ref/Block]):

i=5;
Table[i,{i,1,i}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Module, paclet:ref/Module])  ▪  (RefLink[With, paclet:ref/With])  ▪  (RefLink[CompoundExpression, paclet:ref/CompoundExpression])  ▪  (RefLink[Assuming, paclet:ref/Assuming])  ▪  (RefLink[$Assumptions, paclet:ref/$Assumptions])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Blocks and Local Values, paclet:tutorial/BlocksAndLocalValues])}, {▪(RefLinkPlain[Blocks Compared with Modules, paclet:tutorial/BlocksComparedWithModules])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Package Bulletproofing, paclet:guide/PackageBulletproofing])}, {▪(RefLinkPlain[Package Development, paclet:guide/PackageDevelopment])}, {▪(RefLinkPlain[Cookie Management, paclet:guide/CookieManagement])}, {▪(RefLinkPlain[Scoping Constructs, paclet:guide/ScopingConstructs])}, {▪(RefLinkPlain[Language Overview, paclet:guide/LanguageOverview])}, {▪(RefLinkPlain[Procedural Programming, paclet:guide/ProceduralProgramming])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-FastIntro.png(Spacer1)Fast Introduction for Programmers: Procedures, http://www.wolfram.com/language/fast-introduction-for-programmers/procedures/])}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/38-assigning-names-to-things.html])(WebLink[: Assigning Names to Things, https://www.wolfram.com/language/elementary-introduction/38-assigning-names-to-things.html])}, {(WebLink[DocumentationFooterIconsRelatedLinks-NKS.png(Spacer1)NKS|Online, http://www.wolframscience.com/nksonline/index/search.cgi?SearchIndex=Block]) ((WebLink[A New Kind of Science, http://www.wolframscience.com/nksonline/]))}})}})