Solved

INDENTATION

Posted on 1998-11-14
2
443 Views
Last Modified: 2010-04-01
MORE INFORMATION ABOUT INDENTATION IN c++. Enough to write on the topic.
0
Comment
Question by:BS111498
2 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 20 total points
ID: 1177893
Indentation is only meant to make code more readable, it has no effect on the way a program is compiled.  Indentation is used to make it easier to determine where a block of code begins and ends.  If one block of code contains another block of code, it is generally indented two or three spaces away from the block of code containing it.  Also, indentation is used on individual statements, whether they are in a block or not, when these statements belong to other statements such as for or if.

for (i=0; i<10; i++)
  for (j=0; j<10; j++)
    x += y[i,j];
if (x > 100)
  x -= 100;

is much easier to read than:

for (i=0; i<10; i++)
for (j=0; j<10; j++)
x += y[i,j];
if (x > 100)
x -= 100;

however they both do exactly the same thing.  In the first example you know that the second "for" statement is part of the first "for" statement, and the x += y[i,j] belongs to the second for statement.  Also, you know that the "if" statement is not contained within the first or second "for" statements because it is at the same level of indentation as the first "for" statement.  You can also tell that the statement x =- 100 belongs the the if statement by looking at indentation.  In the same example, you can figure it out by looking closely, but it is much easier and visually appealing to use indentation.


0
 

Author Comment

by:BS111498
ID: 1177894
Scrapdog I am very grateful for the answer, I have search many textbooks for this subject and only about two lines is included.

The question was " indentation causes confusion"

If you have any reference on this subject, please email it to me
                                           thanks BS


























0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question