# Keep running the function without restarting it?

I have this problem that i cannot make run my while(true) without it get restarted..

I think the problem occurs since

in my main loop

int main
{
ros::init(argc,argv, "loop");
loop();
ros::spin();
}


In side loop()

void loop()
{

cout << "Are you ready" << endl;
{

//DO SOMETHING
ros::spinOnce() //needed since i read from a subscriber in this while loop
}

cout << "i am out" << endl;
while(true)
{
//do something again
ros::spinOnce();
}

}


Right now it keep printing "are you ready", the idea was it should print it once.. I don't understand how it comes outside the loop.. it seems impossible to do..

edit retag close merge delete

This code snippet should not produce the output you describe. Maybe you omitted the line which causes your problem. Can you post a more complete code? (e.g. in the line while(ready == false a bracket is missing)