for i=1:10
if(true)
while(true)
i=i+1;
end
end
end
will this increment or update the value of i ?

댓글 수: 2

Stephen23
Stephen23 2018년 4월 25일
@Mushahid Shamim: what happened when you tried it?
Mushahid Shamim
Mushahid Shamim 2018년 4월 25일
I noticed it dont update the value of i.

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

 채택된 답변

Hunter Bates
Hunter Bates 2018년 4월 25일

0 개 추천

@Mushahid Shamim: This will run in a inf loop. Need a condition to break the while statement. for i=1:10 if(true) while(true) i=i+1 break end end end end Please describe the workflow which you are trying to achieve, assuming this isn't for m-code 101

댓글 수: 3

Mushahid Shamim
Mushahid Shamim 2018년 4월 26일
yeah after a while the while block will break. lets say I loop through i=1:10 in for loop and I want to increase i in while block from 1 to 4. while(i<4) i=i+1 end why this is not increasing the value of that i that controlling the outer for loop
why should your while loop break? I am pretty sure that your for loop doesnt even care if you change i somewhere it will still run from 1:10.
If you want your inner loop to iterate 4 times why are you using while?
while it<=10
for i=1:4
it=it+1;
end
end
Mushahid Shamim
Mushahid Shamim 2018년 4월 26일
let's say its another condition and it will break after some iterations. and while it fulfilling the while condition and I want to increase the value of i each time.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2018년 4월 25일

댓글:

2018년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by