How to have two loops running at the same time

Hi, i made humanoid robotic skeleton out of wood, and i use servos and dc motors to move limbs of the bot. I want to run more commands at once analogWrite and servo positioning commands, but i can't find a way to do it. I use this code for servo positioning:
for(pos1 = 0; pos1 < 180; pos1 += 1)
{
servo1.write(pos1);
delay(1000);
}
for(pos1 = 180; pos1>=1; pos1-= 1)
{
servo1.write(pos1);
delay(1000);
}
and i would like to put analogWrite command to run simultaneously with these commands. This might be very simple but idk how to do it, i would appreciate help!

The usual advice: get rid of for loops, get rid of delay() calls, take a look at the blink without delay example.

Stop using delay (look at blink without delay example) or use multiple mcus.

Have a look at the demo Several Things at a Time

...R

Mixailo:
severalthingsatthesametime would definately be a solution and i will use it , but i would like to see more ideas.

Why?

I will use severalthingsatonce, that is very quick solution for my problem.

Is this how it should look with severalthingsatthesametime (i edited code for my needs)? It still works the same, analogWrite is still ignored by the arduino, only servo control is running.

#include <Servo.h>
Servo servo1;
int pos1 = 0;
void setup() {
// put your setup code here, to run once:
servo1.attach(6);
pinMode (5, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
servoKontrola();
usta();

}

void servoKontrola() {

for(pos1 = 0; pos1 < 180; pos1 += 1)
{
servo1.write(pos1);
delay(1000);
}
for(pos1 = 180; pos1>=1; pos1-= 1)
{
servo1.write(pos1);
delay(1000);
}

}

void usta() {

analogWrite (5, 255);
delay (1000);
analogWrite (5, 0);
delay (1000);

}

Please see replies #1, 2 and 3

analogWrite is still ignored by the arduino,

Maybe you're not patient enough.

ok i have looked it up now everything is clear, i look like an idiot right now...

No, you were merely uneducated.
You are educated now.
Neither side of that is idiotic.

Now get busy and fix up your code. We want to see videos of your work!

It works i'll upload video o it working when i optimize it all