return to a previous statement

Guys,in my code I have assigned some values to certain variables and then I did some analysis.The results of analysis, are then checked for some conditions.When the condition is not met, the values will have to be re assigned.My confusion is ,how to go back to the line where values have to be assigned. eg
a=value1 ;b=value2;
%analysis
if (condition)
% code
else %go back to the statement where new values will be assigned i.e at beginning
end

1 comentario

shalvi singh
shalvi singh el 8 de En. de 2019
Hello guys,In my code I have assigned some values to the variables and did analysis and then checked for one variable.If condition met with condition1 then I wanted to assign some statement to a variable and if met with condition2 then wanted to assign some other statement and after both if statements I wanted to run the code from starting,eg;
X=1;Y=1;
%Analysis
if (condition1)
statement1(%go back to starting of the code)
elseif (condition)
statement2(%go back to starting of the code)
end

Iniciar sesión para comentar.

 Respuesta aceptada

James Tursa
James Tursa el 27 de Mzo. de 2015
Editada: James Tursa el 27 de Mzo. de 2015
while( true )
a = value1; b = value2;
% analysis
if( condition )
% code
break
end
end
If the condition is met, the code will break out of the while loop.
If the condition is not met, the code will automatically loop back to the beginning of the while loop.
Note: This loop construct is typically known as a DO-UNTIL loop.

5 comentarios

Ace_ventura
Ace_ventura el 28 de Mzo. de 2015
Thanks James ..Cheers to Life
Arnab Pal
Arnab Pal el 18 de Abr. de 2019
I have more while and for loop, I need to go beginning. ex:
1. while ()
2. for ()
3. if (condition)
4. go back to starting of the code i.e line 1
5. else
6. code for some action
7. end
8. end
9. end
I need like this, Please help.
Steven Lord
Steven Lord el 18 de Abr. de 2019
Use break.
Abel Z
Abel Z el 26 de Nov. de 2020
break doens't work on " if %condition " loop that's my problem...
Image Analyst
Image Analyst el 26 de Nov. de 2020
Post your code in a new question.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 27 de Mzo. de 2015

Comentada:

el 26 de Nov. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by