Block (programming): Difference between revisions

Content deleted Content added
m Reverted 2 edits by 107.77.253.3 (talk) to last revision by Alejandrocaro35. (TW)
Remove two instances of "he or she"
Line 118:
</source>
 
Use of blocks in the above fragment of [[Pascal (programming language)|Pascal]] enablesclarifies the programmer's to be clearer about what he or she intendsintent, and toenables combinecombining the resulting blocks into a nested hierarchy of conditional statements. The structure of the code reflects the programmer's thinking more closely, making it easier to understand and modify.
 
FromThe lookingabove at the abovesource code the programmer can easilybe see that he or she can make the source codemade even clearer by taking the inner if statement out of the outer one altogether, placing the two blocks one after the other to be executed consecutively. Semantically there is little difference in this case, and the use of block structure, supported by indenting for readability, makes it easy for the programmer to refactor the code.
 
In primitive languages, variables had broad scope. For instance, an integer variable called IEMPNO might be used in one part of a Fortran subroutine to denote an employee social security number (ssn), but during maintenance work on the same subroutine, a programmer might accidentally use the same variable, IEMPNO, for a different purpose, and this could result in a bug that was difficult to trace. Block structure makes it easier for programmers to control scope to a minute level.