Is it not possible to run two or more loops in parallel in arduino IDE ?
No. The arduino is single threaded. It's fast though, so you can make it look as though it's doing multiple things at once. The blink without delay example is often touted to show the technique of using millis to control when things happen.
while(1) //1st loop
{
// Some commands which were executed
}
while(2) //2nd loop
In C/C++ the convention is that anything non-zero evaluates to "true", so "while (1)" is an infinite loop.
For the same reason, "while (2)" is also an infinite loop, but is never reached because the first loop never terminates.
void loop()
{
while (condition1 || condition2)
{
if (condition1) //1st block
{
// Some commands which were executed
}
if (condition2) //2nd block
{
// Commands which should no longer fail to execute
}
}
}
The outer while is somewhat redundant, since loop() is a forever loop, but you get the idea.
somanshumehta:
Actually I was working on a small project.I have omitted few functions to make the reader easy to deal with the problem
Actually, it would be better if you posted real code to demonstrate what you're trying to do, even if it doesn't currently do what you want. As it stands, there seems no point to either of your while() loops since "// some commands ..." would be executed repeatedly by virtue of being inside the loop() function anyway.