Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar.
When asking a question about hardware you need to include a schematic and technical data for the components. A hand drawn schematic, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.
What you told it to do was Rotate for 3 seconds in a direction that depends on the IRSensor reading, then pause 1 second. You didn't write the part where it waits for a change in the IRSensor.
If it isn't pausing for one second after three seconds of moving then the wiring or hardware are incorrect.
But the loop continues forever like it runs 3sec and stops 1 sec,I just want the output to be like it should run for 3sec and stop wait for ir signal and then rotate in reverse direction for 3 sec and stop
Good! If it pauses that means your hardware is working. Now you just have to look at the StateChangeDetection example to see how to determine when the input has changed.
It will help us if you could draw a schematic, not a Fritzy image.
An image of a hand drawn circuit would be great.
Please include power supplies, hardware, component names and pin labels.