Music in an If statement

I'm trying to make a buzzer play when I press a button on a 4x4 keypad, but its not working. I'm not sure how to make the song be inside the void loop. Every tutorial I've used makes it so that song is outside the void loop, how to I make it so when I press a key on the keypad a song plays. thank you for your helpin advanced.

post whatever you have tried so far in code tag so it looks like this:

//Your code here

"// Key pad stuff
#include <Keypad.h>
//Pitches For Songs
#include "putches.h"

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};

byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {11, 10, 9, 8}; //connect to the column pinouts of the keypad

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

// set up the light variables
int lightOne = A0;
int lightTwo = A1;
int lightThree = A2;
int lightFour = A3;
int lightFive = A4;
int lightSix = A5;
int lightSeven = 1;
int lightEight = 2;

// set up the speaker
int speakerOUT = 3;

void setup() {
// lights
pinMode(lightOne, OUTPUT);
pinMode(lightTwo, OUTPUT);
pinMode(lightThree, OUTPUT);
pinMode(lightFour, OUTPUT);
pinMode(lightFive, OUTPUT);
pinMode(lightSix, OUTPUT);
pinMode(lightSeven, OUTPUT);
pinMode(lightEight, OUTPUT);
// speaker
pinMode(speakerOUT, OUTPUT);
// serial monitor
Serial.begin(9600);

}

void loop() {

char key = kpd.getKey();

if(key) // Check for a valid key.
{
switch (key) {
// this is set up so you can have anything run inside of the case, and is all the buttons possible on the touch pad.

case '1' : // Very moist selected. moist level=9
Serial.print("Very moist selected. moist level=9");
break;

case '2' : // Good soaking selected. moist level=8
Serial.print("Good soaking selected. moist level=8");
break;

case '3' : // Moist soil selected. moist level=7
Serial.print("");
break;

case '4' : //Thourough watering selected. moist level=6
Serial.print("Moist soil selected. moist level=7");
break;

case '5' : //Lightly moist selected. mosit level=5
Serial.print("Lightly moist selected. mosit level=5");
break;

case '6' : // well drained selected. moist level=4
Serial.print("well drained selected. moist level=4");
break;

case '7' : // Every two days selected. moist level=3
Serial.print("Every two days selected. moist level=3");
break;

case '8' : // very little moisture selected moist level=2
Serial.print("very little moisture selected moist level=2");
break;

case '9' : // dry selected. moisture level=1
Serial.print("dry selected. moisture level=1");
break;

case 'A' :
beep
break;

case 'B' :
break;

case 'C' :
break;

case 'D' :
break;

case '*' :
break;

case '#' :
break;

case '0' :
break;

default: // always prints to the serial monotor what has been pressed.
Serial.println(key);

}

}

}
"

code tags?

With 'buzzer', we usually mean an active device.
A device that makes sound by itself if you connect it to a constant voltage.

Active buzzers can't be used for sound or PWM.
You have to use a 'piezo speaker' (passive device) for that.
Leo..