How to stop the loop once store the 1st value of a variable?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sherif Shokry
am 17 Feb. 2018
Bearbeitet: Sherif Shokry
am 17 Feb. 2018
Dear all, In my code, I need to break the code after recording the 1st value once the condition satisfied. However, when I executed the following code, the "Swt_Tm" variable keep updating for each iteration while the condition is satisfied.
if strcmp (sg_12.get('AttValue','SigState'), 'GREEN')
Swt_Tm= sim.get('AttValue', 'SimSec');
end
0 Kommentare
Akzeptierte Antwort
Birdman
am 17 Feb. 2018
Bearbeitet: Birdman
am 17 Feb. 2018
Use break command inside the condition(note that break command works inside for and while loop):
for ...
%%%code
if strcmp (sg_12.get('AttValue','SigState'), 'GREEN')
Swt_Tm= sim.get('AttValue', 'SimSec');
break;
end
%%%code
end
3 Kommentare
Birdman
am 17 Feb. 2018
while true
if strcmp (sg_12.get('AttValue','SigState'), 'GREEN')
Swt_Tm= sim.get('AttValue', 'SimSec');
break;
end
end
This will break the loop once the if condition is entered.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!