Bird set free

--Originally published at Codebuster

Nesting in programming is defined as:

“Where different logic structures sequence, selection and loop are combined (i.e., nested in one another)

So what this basically means is that nesting is a function within a function. Therefore, a nested conditional would imply a conditional (if/else/elif) inside another conditional (if/elif/else). The funny thing is, a lot of times we use nested conditionals without realizing it, since it can help us break down a function.

nesting-code

As you can see, we use several ifs and elifs inside the main function, which would give us:

nesting-py

You can find some great examples here:

Although nesting can be good for evaluating different conditions at the same time, it can also hinder the program if we use too many of this conditionals. It’s important to remember the zen of python, flat is better than nested.