How to go from if..end to switch..end?
Show older comments
Hi, simple question, how can i go from if..end to switch..end?
soma=0
for j=1:5
if j==2 | j==4
continue
end
soma=soma+j
end
Thank you!
Accepted Answer
More Answers (1)
Kevin Phung
on 21 Jan 2019
Edited: Kevin Phung
on 21 Jan 2019
Not sure what you are doing with your loop, but according to what you have, switching from if/else to switch/case:
soma=0
for j=1:5
switch j
case {2,4} % will check if j is 2 OR 4
continue % if true, then run this
end
soma=soma+j
end
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!