IF statement to be used inside FOR loop with sensor input

hello,
I am new to Arduino,

I want to do the following stuff in Arduino:

  1. Read the signal from sensor and will store it as x. for example x=6.

  2. if x=6, "I want to run two motors one after another after getting a signal from IR sensor and stop". This process should run for X=6 times after each signal input from IR sensor.
    I tried this so many times with IF statement inside FOR loop but failed.

3.The loop should end and wait for next X value. It may be 6 or 12 or any thing.

your help will be appreciated.

Post what you already tried.

Tell is why it fell short of your expectations.

You can use a while loop to wait for the input:

while ( !irrecv.decode(&results) );
x = results.value;

if ( x == 6 ) {
   // Run the motors
}