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
Solved

INDENTATION

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 128
Embarcadero WebBroker REST server endpoint parameters 2 80
gdb doesn't stop on breakpoint 2 92
Outlook 13 41
  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 …
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

808 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