Back to Top

Friday 10 April 2015

Begginer's Guide to C++- Chapter 5: Nesting

I did not intend it to be published so fast. This one was actually on hold till Sunday, but since there was a popular demand, I posted it as soon as possible.

Nesting is really the most essential part of a C++ code. Nesting in itself is not a bit or a piece of code, but is a concept, using which one is able to make more complicated programs, which are closer to the real world model. Today, there will be no new coding and I will try to include as little code as possible.



I was not thinking of posting it as a separate chapter (As I indicated in the previous chapter), but I could not think of naming it chapter 3.1 or 4.1, as nesting is an integral part of C++, and it is easy to learn as well. It is used all the way from if-else statements to for loops.

To understand nesting, just remember the following clause-

“Anything and everything can be placed inside any block”

What I mean by the above statement is that you can place an if-else statement inside a for loop, or a for loop inside a for loop. You are also allowed to place a switch case statement in a do-while loop, which inturn has a for loop in it.

There is no specific syntax for placing something inside anything (I know, its just getting confusing). Just do it as you would normally write a code.

If you had any problem understanding the concept, please comment below!

You will be getting separate examples and practice questions for conditional statements and loops, in further chapters labeled as 5.1, 5.2 ... , till then stay tuned!