Solved

INDENTATION

Posted on 1998-11-14
2
439 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

930 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now