How to make multiple loops?

1 view (last 30 days)
Hi, in my code there are two while loops but when I run the program only on work at a time. my question is: How to make all the loops work together at any moment?
this a sample code for understanding the question:
%%first while loop
count = 0;
while count ~= 1
%%*statements*
pause(1)
end
%%second while loop
count = 0;
while count ~= 1
%%*different_statements*
pause(1)
end
As you can see the loop made to be infinite loop, so when I used two of them in one code only one work at a time.

Accepted Answer

Nicole Peltier
Nicole Peltier on 23 Sep 2018
The two sets of statements (where you put %%*statements* and %%*different_statements*) need to be in the same while loop. The code in the second loop won't start until the first loop terminates (and as you pointed out, the first loop will not terminate). If you want the sets of statements to happen together, there seems to be no reason why you would need two loops.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!