What should i use if i dont want to perform any operation?

조회 수: 7 (최근 30일)
peyush
peyush 2015년 6월 28일
댓글: peyush 2015년 6월 28일
I'm using if, elseif, else conditions...what should I use if for a certain conditions I don't want to perform any operation?....for example:
if condition1
operation1
elseif condition2
no operation
else
operation3
end
so, what code should I use to perform no operation...can any one help?

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 6월 28일
Peyush - use what you have above and just do nothing for the second condition. Write a comment to make it clear that this is intentional.
if condition1
% do operation 1
elseif condition2
% intentionally left blank
else
% do operation 3
end
If this code is within a loop and you want to skip all remaining operations that may follow the above, then just add a continue statement to the elseif block which will skip to the next iteration.

추가 답변 (1개)

Thorsten
Thorsten 2015년 6월 28일
You can rewrite your if-clause as
if condition1
operation1
elseif ~condition2
operation3
end

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by