How to use multiple break statments
Afficher commentaires plus anciens
In the below code if any of the error goes below the limit the loop break. But I want to break the loop if all of the conditions errors are below the defined limits. How can I modify this piece of code.
for i = 1:100
if(sln2.Error<=1)
break
else
% Update weights
Ext.W22=beta*Ext.W22;
Ext.W22List(i) = Ext.W22;
end
%% Convergance Check sub 2
sln3.Error=max(abs(Ext.P_gen_scaling-Ext.P_gen_scaling_3));
SLN3(i)=sln3;
if(sln3.Error<=0.1)
break
else
end
4 commentaires
Rik
le 14 Juil 2021
When I format your question for you, it seems you're missing an end statement. Is this intentional?
Also, what exactly is your question? What exactly do you want to happen?
Sulaymon Eshkabilov
le 14 Juil 2021
As Rik mentioned above one "end" statement is missing. Moreover, the second "else" does nothing and thus, it should be removed.
for i = 1:100
if (sln2.Error<=1)
break
else
% Update weights
Ext.W22=beta*Ext.W22;
Ext.W22List(i) = Ext.W22;
end
%% Convergance Check sub 2
sln3.Error=max(abs(Ext.P_gen_scaling-Ext.P_gen_scaling_3));
SLN3(i)=sln3;
if (sln3.Error<=0.1)
break
end
end
Muhammad Qaisar Fahim
le 14 Juil 2021
Muhammad Qaisar Fahim
le 14 Juil 2021
Réponse acceptée
Plus de réponses (1)
Jan
le 14 Juil 2021
for i = 1:100
Ext.W22 = beta * Ext.W22;
Ext.W22List(i) = Ext.W22;
%% Convergance Check sub 2
sln3.Error = max(abs(Ext.P_gen_scaling - Ext.P_gen_scaling_3));
SLN3(i) = sln3;
if (sln3.Error <= 0.1) && (sln2.Error <= 1)
break
end
end
1 commentaire
Muhammad Qaisar Fahim
le 14 Juil 2021
Modifié(e) : Muhammad Qaisar Fahim
le 14 Juil 2021
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!