Is there a way to call Continue in a loop less script ?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
P Lepage
il 6 Nov 2020
Modificato: P Lepage
il 9 Nov 2020
Is there any way to call a continue statement in a script that does not contain a loop to continue the caller context loop ?
Since script are just chunks of code that will be runned in the caller context and can access it's variable, it would make sence that the continue statement can affect the caller context's loop.
When a continue is written outside a loop, Matlab's interpreter signals an error. That makes sence because the interpreter has no way to know that this script will be runed in a loop. What dosen't makes sence is that the error is thrown when the script is executed in a suitable context.
Any way to prevent this ?
Thank you all for your time.
0 Commenti
Risposta accettata
Abdolkarim Mohammadi
il 6 Nov 2020
Modificato: Abdolkarim Mohammadi
il 6 Nov 2020
Instead of calling continue directly, you can set a flag in the inner script. The outer script, which contains the loop, uses the flag to continue to the next iteration.
for
% ------------
% inner script
if
flag = 1;
else
flag = 0;
end
% ------------
if flag == 1
continue
end
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!