Trying my hardest to understand this.

Okay, so I used some of the code from the original sketch for the "shave and a haircut" audio that came packaged in the Arduino software. I think I have a grasp on what is going here. I have made very detailed comments in helping me to learn about what is going here. Will you guys please read over my comments and tell me if I have anything even a little bit off?

Thank you.

//First tell the program what library(ies) to use.  The file is called from the libraries folder.
#include "pitches.h"

//Then start out by telling the program what notes out of the pitches.h file we will be using.  Since there are numbers used we must state that we
//are using an integer by writing int at the beginning.
int melody[] = {
NOTE_B0, NOTE_C1, NOTE_CS1, NOTE_D1, NOTE_D2, NOTE_DS1, NOTE_DS2, NOTE_E1, NOTE_E2, NOTE_E3, NOTE_F1, NOTE_F2, 
NOTE_FS1, NOTE_FS2, NOTE_FS3, NOTE_G1, NOTE_G2, NOTE_G3, NOTE_GS4, NOTE_GS5, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_AS4, 
NOTE_AS5, NOTE_AS6, NOTE_B1, NOTE_B4, NOTE_B5, NOTE_C2, NOTE_C4, NOTE_C5, NOTE_C6, NOTE_CS2, NOTE_CS4, NOTE_CS5, 
NOTE_CS6, NOTE_D2, NOTE_D4, NOTE_D5, NOTE_D6, NOTE_D7, NOTE_DS2, NOTE_DS4, NOTE_DS5, NOTE_DS6, NOTE_E2, NOTE_E4, 
NOTE_E5, NOTE_E6, NOTE_E7, NOTE_F2, NOTE_F4, NOTE_F5, NOTE_F6, NOTE_F7, NOTE_FS2, NOTE_FS4, NOTE_FS5, NOTE_FS6, 
NOTE_FS7, NOTE_G2, NOTE_G4, NOTE_GS2, NOTE_A2, NOTE_AS2, NOTE_B2, NOTE_C3, NOTE_DS3, NOTE_E3, NOTE_F3, NOTE_FS3, 
NOTE_G3, NOTE_GS3, NOTE_A3, NOTE_AS3, NOTE_B3, NOTE_C4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, 
NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, 
NOTE_AS5, NOTE_B5, NOTE_C6, NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, 
NOTE_AS6, NOTE_B6, NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7, NOTE_G7, NOTE_GS7, NOTE_A7, 
NOTE_AS7, NOTE_B7, NOTE_C8, NOTE_CS8, NOTE_D8, NOTE_DS8};

//Next we need to state how many times we want each tone to play for.  So we say it is
//an integer of course first because we are going to use a number in the string.  Then
//we arbitrarily call it the noteLengths and say that we are going to play each note once.
//Each one of the 1's tells the program to play each note once.  If we only had one 1, it would play 
//all the tones one time, for the amount of time specified (here it's one full tone length which is set
//in thisNote<100).  Since we have 132 tones, we've put the 1 132 separate times.
int noteLengths[] = {
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};

//Now we start the setup so we can play these neat tones we have called up above.
void setup(){
  
  //the "for" statement is causing the integer "thisNote" when it 
  //has the = sign to execute whatever is on the other side of it.  
  //It is set at zero because that is the lowest number we can use
  //before using a negative number.  0 is always the beginning. The 100
  //means that it is a full note, so it's on a scale of 0-100 in this
  //type of equation. The next "thisNote" has a < sign, which means to 
  //test the equation by executing it on pin 5 (pin 5 is set below in the 
  //"tone" statement). Then the final "thisNote" with the ++ simply means 
  //to repeat the process.  Then we open the process that we're going to write up 
  //with the open bracket.
for (int thisNote = 0; thisNote<100; thisNote++){
  
  //Next we're going to need to say just how long we want each "thisNote" to play.
  //So we say that's an integer and call the length "noteDuration".  We say that we
  //need the noteDuration to be one full note, that's why we're dividing the noteDurations
  //by 1 so it will remain a full note.  Then we 
  //state that the 1 full length for the noteDuration is done with thisNote. That means
  //that thisNote is what is playing the tone through your speaker.
  int noteLength = 1000/noteLengths[thisNote];
  
  //Next we're calling the "tone" function as we next need to state how long each tone is played, so we
  //tell it to play on pin 5 first, then we want the full note to be played in the melody
  //by using the notes from thisNote.  For each thisNote in the melody, we need to have it check the noteDuration
  //so it can call the right integer, which is 1 up above (1/noteDurations) so it will play a full note.
  tone (5, melody[thisNote], noteLength);
  
  //Now we want a small delay between the notes so it doesn't sound like one fluid sound going up and down. Unless
  //of course you want to have no space between the tones and have one smooth up and down sound.  Since there is
  //a number in there we have to firstly tell the line of code that there an integer it's going to have to deal with/
  //as well as when the program reaches a number in the string of characters that it will be a whole number (integer).
  //Then we call this the pauseBetweenNotes and say that the pauseBetweenNotes is equal to the noteDuration x 1, basically
  //stating that the pause is the same length as the note itself.
  int pauseBetweenNotes = noteLength * .05;
  
  //Now since we have stated just how long we want the pause to be between the notes, we use the "delay" function to implement
  //the actual pause between the notes.  The reason we put the parenthesis here and not above is because we were just declaring
  //that we intended to use the pauseBetweenNotes below.
  delay (pauseBetweenNotes);
  
  //if you uncomment the next line it will cause the program to stop after running through one time as long as you place
  //this code in void loop().  If this code remains here in void setup() it will only run one time regardless if you have
  //the line below in there or not.
  //noTone(5);
  
}
}
void loop(){
}
... // so it's on a scale of 0-100 in this

//type of equation. The next "thisNote" has a < sign, which means to
  //test the equation by executing it on pin 5 (pin 5 is set below in the
  //"tone" statement).
...
for (int thisNote = 0; thisNote<100; thisNote++){

0 to 99, not 0 to 100. Since it goes to "less than" 100 it stops at 99.

It does it 100 times (0 to 99 is 100 iterations) but it doesn't reach 100.

I just began to have problems with that over the last few minutes and realized that there was something with 99. Thank you for your feedback. Again, trying my hardest.

One other thing, this is the code i'm using now and i've noticed that the LED will not turn off after the iteration is over. Why not?

//First tell the program what library(ies) to use.  The file is called from the libraries folder.
#include "pitches.h"

//Then start out by telling the program what notes out of the pitches.h file we will be using.  Since there are numbers used we must state that we
//are using an integer by writing int at the beginning.
int melody[] = {
NOTE_B0, NOTE_C1, NOTE_CS1, NOTE_D1, NOTE_D2, NOTE_DS1, NOTE_DS2, NOTE_E1, NOTE_E2, NOTE_E3, NOTE_F1, NOTE_F2, 
NOTE_FS1, NOTE_FS2, NOTE_FS3, NOTE_G1, NOTE_G2, NOTE_G3, NOTE_GS4, NOTE_GS5, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_AS4, 
NOTE_AS5, NOTE_AS6, NOTE_B1, NOTE_B4, NOTE_B5, NOTE_C2, NOTE_C4, NOTE_C5, NOTE_C6, NOTE_CS2, NOTE_CS4, NOTE_CS5, 
NOTE_CS6, NOTE_D2, NOTE_D4, NOTE_D5, NOTE_D6, NOTE_D7, NOTE_DS2, NOTE_DS4, NOTE_DS5, NOTE_DS6, NOTE_E2, NOTE_E4, 
NOTE_E5, NOTE_E6, NOTE_E7, NOTE_F2, NOTE_F4, NOTE_F5, NOTE_F6, NOTE_F7, NOTE_FS2, NOTE_FS4, NOTE_FS5, NOTE_FS6, 
NOTE_FS7, NOTE_G2, NOTE_G4, NOTE_GS2, NOTE_A2, NOTE_AS2, NOTE_B2, NOTE_C3, NOTE_DS3, NOTE_E3, NOTE_F3, NOTE_FS3, 
NOTE_G3, NOTE_GS3, NOTE_A3, NOTE_AS3, NOTE_B3, NOTE_C4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, 
NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, 
NOTE_AS5, NOTE_B5, NOTE_C6, NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, 
NOTE_AS6, NOTE_B6, NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7, NOTE_G7, NOTE_GS7, NOTE_A7, 
NOTE_AS7, NOTE_B7, NOTE_C8, NOTE_CS8, NOTE_D8, NOTE_DS8};

//Next we need to state how many times we want each tone to play for.  So we say it is
//an integer of course first because we are going to use a number in the string.  Then
//we arbitrarily call it the noteLengths and say that we are going to play each note once.
//Each one of the 1's tells the program to play each note once.  If we only had one 1, it would play 
//all the tones one time, for the amount of time specified (here it's one full tone length which is set
//in thisNote<100).  Since we have 132 tones, we've put the 1 132 separate times.
int noteLengths[] = {
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
int ledPin = 8;

//Now we start the setup so we can play these neat tones and LED light we have called up above.
void setup(){

  //This sets the ledPin to actually turn on.
pinMode (ledPin, OUTPUT);

  //the "for" statement is causing the integer "thisNote" when it 
  //has the = sign to execute whatever is on the other side of it.  
  //It is set at zero because that is the lowest number we can use
  //before using a negative number.  0 is always the beginning. The 100
  //means that it is a full note, so it's on a scale of 0-99 in this
  //type of equation. The next "thisNote" has a < sign, which means to 
  //test the equation by executing it on pin 5 (pin 5 is set below in the 
  //"tone" statement). Then the final "thisNote" with the ++ simply means 
  //to repeat the process.  Then we open the process that we're going to write up 
  //with the open bracket.

for (int thisNote = 0; thisNote<99; thisNote++){  
 
 //Next we're going to say that if thisNote is being played and is less than or
 //equal to 98 that we want to turn the ledPin on or HIGH, else if it's not on it's off or LOW.
 
  if (thisNote<=99){
    digitalWrite(ledPin, HIGH);
  }
  else {
    digitalWrite(ledPin, LOW);
  }

  //Next we're going to need to say just how long we want each "thisNote" to play.
  //So we say that's an integer and call the length "noteDuration".  We say that we
  //need the noteDuration to be one full note, that's why we're dividing the noteLengths
  //by 1 so it will remain a full note.  Then we 
  //state that the 1 full length for the noteLength is done with thisNote. That means
  //that thisNote is what is playing the tone through your speaker.
  int noteLength = 1000/noteLengths[thisNote];

  //Next we're calling the "tone" function as we next need to state how long each tone is played, so we
  //tell it to play on pin 5 first, then we want the full note to be played in the melody
  //by using the notes from thisNote.  For each thisNote in the melody, we need to have it check the noteLength
  //so it can call the right integer, which is 1 up above (1/noteLengths) so it will play a full note.
  tone (5, melody[thisNote], noteLength);
  
  //Now we want a small delay between the notes so it doesn't sound like one fluid sound going up and down. Unless
  //of course you want to have no space between the tones and have one smooth up and down sound.  Since there is
  //a number in there we have to firstly tell the line of code that there an integer it's going to have to deal with/
  //as well as when the program reaches a number in the string of characters that it will be a whole number (integer).
  //Then we call this the pauseBetweenNotes and say that the pauseBetweenNotes is equal to the noteLength x 1, basically
  //stating that the pause is the same length as the note itself.
  int pauseBetweenNotes = noteLength * 0.05;

  //Now since we have stated just how long we want the pause to be between the notes, we use the "delay" function to implement
  //the actual pause between the notes.  The reason we put the parenthesis here and not above is because we were just declaring
  //that we intended to use the pauseBetweenNotes below.
  delay (pauseBetweenNotes);
  
  //if you uncomment the next line it will cause the program to stop after running through one time as long as you place
  //this code in void loop().  If this code remains here in void setup() it will only run one time regardless if you have
  //the line below in there or not.
  //noTone(5);
  
}
}
void loop(){
}

jakekid:
One other thing, this is the code i'm using now and i've noticed that the LED will not turn off after the iteration is over. Why not?

 if (thisNote<=99){

should be

 if (thisNote<99){

thisNote value goes from 0 to 99 then drops out of the for loop but your checking if it's 'less than or equal to 99' (that it always is). Changing to check 'less than 99' means your last pass through the for loop (thisNote = 99) will turn the LED off.

Actually I just figured it out, if you put it like this then it works perfectly. Please look carefully and let me know if I have made it incorrectly.

//First tell the program what library(ies) to use.  The file is called from the libraries folder.
#include "pitches.h"

//Then start out by telling the program what notes out of the pitches.h file we will be using.  Since there are numbers used we must state that we
//are using an integer by writing int at the beginning.
int melody[] = {
NOTE_B0, NOTE_C1, NOTE_CS1, NOTE_D1, NOTE_D2, NOTE_DS1, NOTE_DS2, NOTE_E1, NOTE_E2, NOTE_E3, NOTE_F1, NOTE_F2, 
NOTE_FS1, NOTE_FS2, NOTE_FS3, NOTE_G1, NOTE_G2, NOTE_G3, NOTE_GS4, NOTE_GS5, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_AS4, 
NOTE_AS5, NOTE_AS6, NOTE_B1, NOTE_B4, NOTE_B5, NOTE_C2, NOTE_C4, NOTE_C5, NOTE_C6, NOTE_CS2, NOTE_CS4, NOTE_CS5, 
NOTE_CS6, NOTE_D2, NOTE_D4, NOTE_D5, NOTE_D6, NOTE_D7, NOTE_DS2, NOTE_DS4, NOTE_DS5, NOTE_DS6, NOTE_E2, NOTE_E4, 
NOTE_E5, NOTE_E6, NOTE_E7, NOTE_F2, NOTE_F4, NOTE_F5, NOTE_F6, NOTE_F7, NOTE_FS2, NOTE_FS4, NOTE_FS5, NOTE_FS6, 
NOTE_FS7, NOTE_G2, NOTE_G4, NOTE_GS2, NOTE_A2, NOTE_AS2, NOTE_B2, NOTE_C3, NOTE_DS3, NOTE_E3, NOTE_F3, NOTE_FS3, 
NOTE_G3, NOTE_GS3, NOTE_A3, NOTE_AS3, NOTE_B3, NOTE_C4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, 
NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, 
NOTE_AS5, NOTE_B5, NOTE_C6, NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, 
NOTE_AS6, NOTE_B6, NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7, NOTE_G7, NOTE_GS7, NOTE_A7, 
NOTE_AS7, NOTE_B7, NOTE_C8, NOTE_CS8, NOTE_D8, NOTE_DS8};

//Next we need to state how many times we want each tone to play for.  So we say it is
//an integer of course first because we are going to use a number in the string.  Then
//we arbitrarily call it the noteLengths and say that we are going to play each note once.
//Each one of the 1's tells the program to play each note once.  If we only had one 1, it would play 
//all the tones one time, for the amount of time specified (here it's one full tone length which is set
//in thisNote<=99).  Since we have 132 tones, we've put the 1 132 separate times.
int noteLengths[] = {
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};

//Again, we set the LED pin to turn on with a command on pin 8. Since there's a number here we have to
//declare that with the int at the beginning.
int ledPin = 8;

//Now we start the setup so we can play these neat tones and LED light we have called up above.
void setup(){

  //This sets the ledPin to actually turn on.
pinMode (ledPin, OUTPUT);

  //the "for" statement is causing the integer "thisNote" when it 
  //has the = sign to execute whatever is on the other side of it.  
  //It is set at zero because that is the lowest number we can use
  //before using a negative number.  0 is always the beginning. The 99
  //means that it is a full note, so it's on a scale of 0-99 in this
  //type of equation (100 units). The next "thisNote" has a <= sign, which means to 
  //test the equation by executing it on pin 5 as a less than or equal to
  //equation (pin 5 is set below in the "tone" statement). Then the final
  //"thisNote" with the ++ simply means to repeat the process.  Then we 
  //open the process that we're going to write up with the open bracket.

for (int thisNote = 0; thisNote<=99; thisNote++){  
 
 //Next we're going to say that if thisNote is being played and is less than 99
 //that we want to turn the ledPin on or HIGH, else if it's not on it's off or LOW.
 
  if (thisNote<99){
    digitalWrite(ledPin, HIGH);
  }
  else {
    digitalWrite(ledPin, LOW);
  }

  //Next we're going to need to say just how long we want each "thisNote" to play.
  //So we say that's an integer and call the length "noteLength".  We say that we
  //need the noteLength to be one full note, that's why we're dividing the noteLengths
  //by 1 so it will remain a full note.  Then we state that the 1 full length for the 
  //noteLength is done with thisNote. That means
  //that thisNote is what is playing the tone through your speaker.
  int noteLength = 1000/noteLengths[thisNote];

  //Next we're calling the "tone" function as we next need to state how long each tone is played, so we
  //tell it to play on pin 5 first, then we want the full note to be played in the melody
  //by using the notes from thisNote.  For each thisNote in the melody, we need to have it check the noteLength
  //so it can call the right integer, which is 1 up above (1/noteLengths) so it will play a full note.
  tone (5, melody[thisNote], noteLength);
  
  //Now we want a small delay between the notes so it doesn't sound like one fluid sound going up and down. Unless
  //of course you want to have no space between the tones and have one smooth up and down sound.  Since there is
  //a number in there we have to firstly tell the line of code that there an integer it's going to have to deal with/
  //as well as when the program reaches a number in the string of characters that it will be a whole number (integer).
  //Then we call this the pauseBetweenNotes and say that the pauseBetweenNotes is equal to the noteLength x 1, basically
  //stating that the pause is the same length as the note itself.
  int pauseBetweenNotes = noteLength * 0.05;

  //Now since we have stated just how long we want the pause to be between the notes, we use the "delay" function to implement
  //the actual pause between the notes.  The reason we put the parenthesis here and not above is because we were just declaring
  //that we intended to use the pauseBetweenNotes below.
  delay (pauseBetweenNotes);
  
  //if you uncomment the next line it will cause the program to stop after running through one time as long as you place
  //this code in void loop().  If this code remains here in void setup() it will only run one time regardless if you have
  //the line below in there or not.
  //noTone(5);
  
}
}
void loop(){
}