4
Answers

Efficiency of Loop Statements

jc mandapat

jc mandapat

18y
4k
1
Can anyone help me with this problem.Let's sat I want to loop 10 employees using the foreach statement.Under the foreach i have 3 functions that computes their wages,tax and deductions. My question is this.which is more efficient? 1. for every 1 employee, I compute their wages, tax and deductions Ex. Foreach (X in dsEmployees) { Compute Wages(); Compute Taxes(); Compute Deductions(); } 2. I compute all the wages for all employees, all taxes for all employees and all deductions for all employees Ex. Foreach (X in dsEmployees) { Compute Wages(); } Foreach (X in dsEmployees) { Compute Taxes(); } Foreach (X in dsEmployees) { Compute Deductions(); } can anyone help? thanks!
Answers (4)