Solved

INDENTATION

Posted on 1998-11-14
2
445 Views
Last Modified: 2010-04-01
MORE INFORMATION ABOUT INDENTATION IN c++. Enough to write on the topic.
0
Comment
Question by:BS111498
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

632 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