How can I run a for loop unless a condition is met

조회 수: 4 (최근 30일)
Caroline
Caroline 2014년 10월 3일
답변: the cyclist 2014년 10월 4일
I am trying to run a for loop that starts at 2 and increments by 1 to 4 and it is inside a while loop that ends if q=2. What I'm trying to do is exit the whole program or start the while loop over even if the for loop hasn't gotten to 4 yet. Heres what I have
for i=2:4
if (i==2)
g=input('Enter guess 2');
if (g>x)
disp('Your guess was too big')
elseif (g==x)
disp('You Win!')
w=w+1;
e=input('To play again enter 1, To quit enter 4');
switch e
case 1
q=1;
case 4
q=2;
end
  댓글 수: 1
Muhammad Zaheer
Muhammad Zaheer 2014년 10월 3일
I don't understand the use of the for loop here since the body of the loop executes only when i is equal to two.

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
the cyclist 2014년 10월 4일
I don't understand this code in the least, but I can make a guess from your description that you want either the break command or the continue command.
doc break
and
doc continue
for details.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by