필터 지우기
필터 지우기

Can't get my while-loop to work

조회 수: 1 (최근 30일)
Felicia Adamsson
Felicia Adamsson 2022년 5월 9일
답변: Harsha Kalavakolu 2022년 5월 12일
Hi, I have a problem with my while-loop. I want to add 1000 to m_tank until T_max_saffle is below 100. After that I want to extract how much the new value of m_tank_saffle is. What am I doing wrong?
Thanks!
antal_tank_saffle=[1]
while T_max_saffle > 100
m_tank_saffle=m_tank+1000;
antal_tank_saffle=[antal_tank_saffle [m_tank_saffle]]
end
  댓글 수: 1
Torsten
Torsten 2022년 5월 9일
편집: Torsten 2022년 5월 9일
If you don't make changes to T_max_saffle in the while loop for that it decreases to a value <= 100, you will never exit the while loop.

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

채택된 답변

Harsha Kalavakolu
Harsha Kalavakolu 2022년 5월 12일
Hi Felicia
As I can understand from your code you are using T_max_saffle > 100 as your loop exiting/Termination condition but it is not getting updated anywhere inside the loop.
If T_max_saffle is >100 from the beginning then your code execution does not enter the while loop, else If T_max_saffle< 100 code execution enters the loop and never exists which means you are stuck in an infinite loop.
So, you have to update T_max_saffle for every iteration based upon your requirement to end the loop.
Hope it helps

추가 답변 (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