Thread: A Looped Array Or If Statements?

1. A Looped Array Or If Statements?

Hi:::

I am relatively new to programming and am trying to assemble a project that involves some math calculations.

I have a set of A values that I want divided by B values, each contain about 13 constants. And each set contains the same constants.

A values (12, 18, 21 etc.)
B values (12, 18, 21 etc)

the code preceding this calculates an answer and looks for corresponding values from A and B that fulfils that answer (it deals with slopes).

I could find every possible slope combination that A and B fulfills such as 12/12, 12/18, 12/21 , 18/12, 18/18 etc. and preload the program with IF statements ? I am assuming there is about 20 combination answers. Does extensive IF statments bog down the program?

Or would it be better to run a looped array?

Thank you for your time in responding!

2. Originally Posted by LLINE
I could find every possible slope combination that A and B fulfills such as 12/12, 12/18, 12/21 , 18/12, 18/18 etc. and preload the program with IF statements ?
You could, but what's the point of that? What's the point of the program then?

I am assuming there is about 20 combination answers. Does extensive IF statments bog down the program?
Yes and no. For you, it would hardly matter one bit. In time critical code, yes, it would probably matter.

Or would it be better to run a looped array?
A loop + array would be much better, I think.
Less code to type, less code to maintain, less error prone.

3. Originally Posted by LLINE
I am relatively new to programming

Does extensive IF statments bog down the program?
Don't worry about optimizing your code, just write the cleanest solution you can. Premature optimization is generally considered a no-no, but later you'll learn some "preemptive optimizations" that may be more sensible to apply, especially if you are developing real-time software, games, etc.

But for now, strive for clean, robust code.

Thanks!