How to spot infinite loops
9 views (last 30 days)
Show older comments
I am working on feature extraction for eeg data. However, everytime I run the code it just keep percolating through the 4th file for the same first 10/56 features. I have checked all the for loops to make sure they have the appropriate end to them. It looks like its working for the first file and it will try to go to file two and then it just redoes that file over and over only for the first 10 features.
0 Comments
Answers (1)
Walter Roberson
on 20 Jan 2025
for loops are never infinite.
while loops are potentially infinite. You need to ensure that for sure at some point at least one of the variables involved in the test is changed. Or if you use while true that there is an if ... break that will definitely get triggered at some point.
A common mistake is to have a while loop inside another loop, but to forget to reset the initial conditions of the while loop. That said, most of the time that this mistake occurs, the problem becomes that the while loop body is not performed for the second and following iterations of the outer loop.
0 Comments
See Also
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!