필터 지우기
필터 지우기

Switch case transition statement

조회 수: 2 (최근 30일)
Nafila Farheen
Nafila Farheen 2019년 12월 2일
답변: Image Analyst 2019년 12월 2일
Hi, I am trying to genertae a switch ..case statement
Switch switchExpression
case 1
if
ifConditionstatemnet /If this is true, give output
else
elseCondition / If this is true, it will jump to case 2
case 2
caseStatement
end
I am trying to figure out how to make the transition from else statement to case 2. Any idea owuld be appreciated. Thanks !

답변 (2개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 12월 2일
I assume you have multiple cases
n=input('Enter the case number: ');
switch n
case 1
if Conditionstatemnet/If this is true,
%give output
elseif Condition / If this is true,
%it will jump to case 2
% Case 2 statements, no need to jump to case 2, just execute here
%caseStatement
else
;
end
case 2
%%%
end

Image Analyst
Image Analyst 2019년 12월 2일
Try it this way, with an if instead of a switch
if switchExpression && ifConditionstatemnet
% Run code for case 1, give output.
else
% Run code for case 2
caseStatement
end
Otherwise if you want to do that complicated way of combining switch and if (which I would not recommend here), you could call a function in those two places where case 2 code needs to be run (again, not recommended).

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by