While loop inside void loop() causing problems

The Problem with the IF option that u presented is that...once the IF loop executes, it will return to MQTTclient.loop and again I will have to give a command from MQTT to start the motion sensor for it to run again.

Which i don't want. What I want is...Once I give a command and the motion sensor initializes, it should run in a loop TILL the time motion is detected. And then exit the loop.

Anyways..I figured out a way to do this task. I just declared another function and called it from within the void loop(). Theoretically, its the same thing and the problem should persist. But it seems to work.

Now another major problem I am facing is the False Detections!! The PIR motion sensor gives soooo much False Detection!! Its annoying really!