티스토리 뷰

1. Syntax

  • while 조건
  •     구문
  • end
i = 0;
total = 0;
while i < 100
    i = i + 1;
    total = total + i;
end

disp(total);

2. Skip to Next Iteration

  • continue 키워드를 통해 다음 loop로 넘어갈 수 있음
i = 0;
total = 0;
while i < 100
    i = i + 1;
    if mod(i, 2) == 0
        continue
    end
    total = total + i;
end

disp( total);

3. Exit loop Before Expression Is False

  • break 키워드를 통해 loop를 탈출
limit = 0.8;
s = 0;

while 1
    tmp = rand;
    if tmp > limit
        break
    end
    s = s + tmp;
end


Reference: https://www.mathworks.com/help/matlab/ref/while.html

'Computer Language > Matlab' 카테고리의 다른 글

2d 그래프(plot)  (0) 2018.08.04
if 문(if statements)  (0) 2018.08.02
for 문(for loop)  (0) 2018.07.31
함수(Function)  (0) 2018.07.28
형태 변형(Reshape and Rearrange)  (0) 2018.07.27
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/12   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함