One of the most common statements or keywords used is the "if" statement. It usually has this syntax: "If = true then (do this) else (do that)" Here's an example so that you can clearly see how it functions.
If C = true then
print A
else
print B
end if
In this program snippet, if C is true then it will print A. If not, it will print B. This is simple and common. However, what if you need to test several values and display different outputs for each. It'll be troublesome especially if you have lots of values to test. A nesting "if" consists of "if" statements within several "if" statements.
You'll have a hard time debugging the program if the output isn't what you intended. It may be difficult to look at where the problem is. But what if someone else reviews your code? They're most likely going to get confused. Just take a look at this one. This is a very simple nesting if.
If C = true then
If D = true then
print A
if G = true then
print A
else
print B
end if
else
print B
end if
else
if E = true then
if F = true then
print A
else
print B
end if
else
print B
end if
end if
As you can see, it's going to be hard to debug since there are lots of conditions to test. This is somewhat easy since the indentions can help you identify which condition belongs to which "if" statement. If I remember correctly, I experienced having 50 or more "If" statements in one of my very old programs around a decade ago.
Probably the best way to work around the nesting "if" is to use a case, select or a similar functioning statement. If you have a similar condition in a lot of "if" statements, using a case statement will be very helpful. Here's a general example to give you an idea but not necessarily the correct syntax.
Case A
1: Print 1
2: Print 2
3: Print 3
4: Print 4
End Case
In previous example, if variable A has a value of 3, it prints 3. You don't have to put in 4 "if" statements just to test A. It'll waste space and doesn't really look good.
One aspect of program coding is to make it as compact but as efficient as possible. It should be optimized so that disk space is not wasted. However, there may be cases wherein there's no choice but to use nesting "ifs". One particular example is when the output is dependent on a previous condition and so on. The best way, as I said before, would most likely be to make use of indentation to identify each "if" statement.
And most importantly, as a programmer, I highly suggest you plan ahead before doing multiple or nesting "if" statements. This way, you won't get confused while coding and you can easily simulate the conditions as if it were running in real-time. This will make it faster and easier for you to code.
Published by Aaron Tadeo
Writing has become one of my hobbies and I really love the feeling when I share my experiences and knowledge as a freelance writer. I'm currently working as a customer service rep. I love computers and been... View profile
- Applying to Graduate School? - Tips for a Strong Statement of PurposeA Statement of Purpose (also known as a Personal Statement) is not what many graduate applicants believe it to be. Here is comprehensive advice on what to include in this very important portion of your application....
- HUD-1 Settlement Statement Part IThe HUD-1 Settlement Statement is required to be used in all real estate closings. This article will look at the sellers' side of the statement and explain some of the entries.
- College Life: How to Write a Personal Statement for College Admission It literally took me weeks to perfect my personal statement for college admission, but I learned several ways to make writing the personal statement for college admission easier and more enjoyable and I will share wit...
- Print AdsI'm going to be quickly outlining for you a good solid collection of my most effective copywriting and print ad design guidelines.
The Logo & Print Catalog for Busy DesignersWhat will you get following the guide? Simple: A strong, clean catalog page template for your print products to be quickly and easily referenced by your customers.
- Ignoring the Fine Print Can Cost You a Mint
- The Principles of Batch Process Program Development: IF Statements (Beginner)
- Writing a Mission Statement that Fits Your Strategic Plan
- A College Personal Statement Example
- Example Personal Statement to Study Abroad in Hong Kong
- How to Get Money Back Early from Your Yearly Escrow Statement
- Creative Writing - Writing Your Thesis Statement



