- A CONTINUE may only be used within a FOR or WHILE loop
- Logical comparison requires 2 equals: d==1 && r>1
A switch case with multiple results or switch expressions?
조회 수: 48 (최근 30일)
이전 댓글 표시
Is such a switch case possible? If not, whats my workaround for it?
switch r,d
case d=1 && r=1
continue
case d=1 && r>1
disp('zero')
case d=0 && r=1
disp('positive one')
case d=0 && r>1
disp('other value')
end
댓글 수: 0
채택된 답변
Cris LaPierre
2020년 12월 23일
First we need to fix some syntax issues.
One way to swtich based on the value of multiple variables is this:
r = 1;
d = 0;
switch true
case d==1 && r>1
disp('zero')
case d==0 && r==1
disp('positive one')
case d==0 && r>1
disp('other value')
end
댓글 수: 1
Walter Roberson
2020년 12월 23일
It is true that a continue can only be used within for or while, but we could speculate that this switch logic is indeed inside a loop.
추가 답변 (1개)
Walter Roberson
2020년 12월 23일
switch true
case d==1 && r==1
continue
case d==1 && r>1
disp('zero')
case d==0 && r==1
disp('positive one')
case d==0 && r>1
disp('other value')
otherwise
disp('Uh-oh!')
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!