Increment the value inside another loop

4 Ansichten (letzte 30 Tage)
Mushahid Shamim
Mushahid Shamim am 25 Apr. 2018
Kommentiert: Mushahid Shamim am 26 Apr. 2018
for i=1:10
if(true)
while(true)
i=i+1;
end
end
end
will this increment or update the value of i ?
  2 Kommentare
Stephen23
Stephen23 am 25 Apr. 2018
@Mushahid Shamim: what happened when you tried it?
Mushahid Shamim
Mushahid Shamim am 25 Apr. 2018
I noticed it dont update the value of i.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Hunter Bates
Hunter Bates am 25 Apr. 2018
@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 Kommentare
Dennis
Dennis am 26 Apr. 2018
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 am 26 Apr. 2018
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

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!

Translated by