while loop; a small problem

1 Ansicht (letzte 30 Tage)
antonet
antonet am 21 Aug. 2012
Dear all,
I have the following statement
k=1;
while abs(k) >= 1
'excecute'
end
the above code is included inside a main loop
I observe though that when k=1; is outside the main loop the algorithm does not get stuck. When I include it inside the main loop after some iterations it gets stuck.
Would it be wrong to put it outiside loop?
thanks
  3 Kommentare
Jürgen
Jürgen am 21 Aug. 2012
And what does the main loop do? It probably influence the value of k in one of both loops...
Jan
Jan am 21 Aug. 2012
The description "when I include it insie the loop" is clear for you, but not clear for us. Please post the code you are talking about.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Matt Fig
Matt Fig am 21 Aug. 2012
This loop, as you written it, should always 'get stuck' because k does not change inside the loop. What are you trying to do with this loop? Do you just want to print the word execute to the screen once through the outer loop?
  3 Kommentare
Jan
Jan am 21 Aug. 2012
No. 'execute' is a string.
Matt Fig
Matt Fig am 21 Aug. 2012
Bearbeitet: Matt Fig am 21 Aug. 2012
Jan is correct. I think you are not doing what you think you are doing! The ONLY way I can see that this loop would not hang when inside another loop is if it is actually inside a conditional that isn't getting met....

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by