Can anyone explain why an Infinite loop is added to prevent main() from exiting
//Prevent main from exiting with an infinite loop.
while(1) {
vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
}
Can anyone explain why an Infinite loop is added to prevent main() from exiting
//Prevent main from exiting with an infinite loop.
while(1) {
vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
}
@Devasena the while(1) is to keep main running. If it isn’t there, the program will end. Sometimes you want it to keep your program alive till you power off the Brain.
However, due to a design decision @jpearman mentioned
you actually don’t have to keep main() from exiting to keep the program running. As long as another thread/task has been started and is running, the program will keep running. So a lot of those
//Prevent main from exiting with an infinite loop.
while(1) {
vex::task::sleep(100); //Sleep the task for a short amount of time to prevent wasted resources.
}
bits I’ve seen are completely unnecessary.
Thanks all for the explanation.It helps!