Why is indentation important? How carefully does the compiler pay attention to

  • 0 replies
  • 514 views
*

Offline mechanic

  • Engineer
  • *****
  • 3420
  • Gender: Male
  • Engineer
    • View Profile
    • Engineering Forum
Why is indentation important? How carefully does the compiler pay attention to it?


Answer:



Indentation is important to show the logical structure of source code, in particular, to show which parts--the ``bodies`` of loops, if/else statements, and other control flow constructs--are subsidiary to which other parts.


Indentation is notspecially observed by the compiler; it treats all ``white space''the same. Code which is improperly indented will give a human reader a mistaken impression of the structure of the code, an impression potentially completely different from the compilers. Therefore, it's important that the punctuation which describes the block structure of code to the compiler matches the indentation.