niraj pateI

Greenhorn

Posts: 5

posted 3 years ago

public void Calculate()

{

frequency[0] = middleC;

frequency[1] = middleC * (Math.pow(2,(0.0833)));

frequency[2] = frequency[1] * (Math.pow(2,(0.0833)));

frequency[3] = frequency[2] * (Math.pow(2,(0.0833)));

frequency[4] = frequency[3] * (Math.pow(2,(0.0833)));

frequency[5] = frequency[4] * (Math.pow(2,(0.0833)));

frequency[6] = frequency[5] * (Math.pow(2,(0.0833)));

frequency[7] = frequency[6] * (Math.pow(2,(0.0833)));

frequency[8] = frequency[7] * (Math.pow(2,(0.0833)));

frequency[9] = frequency[8] * (Math.pow(2,(0.0833)));

frequency[10] = frequency[9] * (Math.pow(2,(0.0833)));

frequency[11] = frequency[10] * (Math.pow(2,(0.0833)));

frequency[12] = frequency[11] * (Math.pow(2,(0.0833)));

frequency[13] = frequency[12] * (Math.pow(2,(0.0833)));

}

{

frequency[0] = middleC;

frequency[1] = middleC * (Math.pow(2,(0.0833)));

frequency[2] = frequency[1] * (Math.pow(2,(0.0833)));

frequency[3] = frequency[2] * (Math.pow(2,(0.0833)));

frequency[4] = frequency[3] * (Math.pow(2,(0.0833)));

frequency[5] = frequency[4] * (Math.pow(2,(0.0833)));

frequency[6] = frequency[5] * (Math.pow(2,(0.0833)));

frequency[7] = frequency[6] * (Math.pow(2,(0.0833)));

frequency[8] = frequency[7] * (Math.pow(2,(0.0833)));

frequency[9] = frequency[8] * (Math.pow(2,(0.0833)));

frequency[10] = frequency[9] * (Math.pow(2,(0.0833)));

frequency[11] = frequency[10] * (Math.pow(2,(0.0833)));

frequency[12] = frequency[11] * (Math.pow(2,(0.0833)));

frequency[13] = frequency[12] * (Math.pow(2,(0.0833)));

}

niraj pateI

Greenhorn

Posts: 5

posted 3 years ago

That was really a hint, more than an actual question.

Any time you see a hunk of code doing the same thing over and over and over, with the only difference being the index of an array, you should think "How can I write this using a loop of some kind".

Note that this line:

could have been written like this:

Any time you see a hunk of code doing the same thing over and over and over, with the only difference being the index of an array, you should think "How can I write this using a loop of some kind".

Note that this line:

could have been written like this:

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

Campbell Ritchie

Marshal

Posts: 56536

172