How to Make Two Loops that Run simultaneously?

Hello,
I want to Make Two Loops that Run simultaneously
I have two PWM Pins Connected to Speakers and I want to make first speaker to play first music and second speaker to play second music.

int speaker1 = 9;
int speaker2 = 10;
void setup()
{
   pinMode(speaker1, OUTPUT);
   pinMode(speaker2, OUTPUT);
}

void loop1()
{
   //speaker1 pin MUSIC
   tone(speaker1, 5000);
   delay(256);
   ...........................
}

void loop2()
{
   //speaker2 pin MUSIC
   tone(speaker2, 3454);
   delay(542);
   ...........................
}

How to make loop1 and loop2 run together?

How to make loop1 and loop2 run together?

Using delay()? You can't. Forget it.

Using the philosophy from the blink with delay example and a state machine, it would be easy.

In loop(), call loop1() (after you give the function a meaningful name) and call loop2() (after you give the function a meaningful name). Each function should figure out if it is time to do something different. If not, it should just return. If so, it should do it, and then return. NO delay() calls allowed.

PaulS:

How to make loop1 and loop2 run together?

Using delay()? You can't. Forget it.

Using the philosophy from the blink with delay example and a state machine, it would be easy.

In loop(), call loop1() (after you give the function a meaningful name) and call loop2() (after you give the function a meaningful name). Each function should figure out if it is time to do something different. If not, it should just return. If so, it should do it, and then return. NO delay() calls allowed.

if i will remove delay and change my code to this:

int speaker1 = 9;
int speaker2 = 10;
void setup()
{
   pinMode(speaker1, OUTPUT);
   pinMode(speaker2, OUTPUT);
}

void loop()
{
   loop1();
   loop2();
}
void loop1()
{
   //speaker1 pin MUSIC
   tone(speaker1, 5000, 256);
   ...........................
}

void loop2()
{
   //speaker2 pin MUSIC
   tone(speaker2, 3454, 542);
   ...........................
}

will it work?

if i will remove delay and change my code to this...will it work?

You've got the Arduino with speakers. You test it.

But, I doubt it. It really all depends on what

....................................

is.