Hi guys. I was doing my assignment (Sierpenski triangle) and i solved it in two ways. switch case ans if-elseif-else. Which one do you think is more logical( less error)?

 Akzeptierte Antwort

Sai Sri Harsha Vallabhuni
Sai Sri Harsha Vallabhuni am 14 Jul. 2020

0 Stimmen

In general, using a switch case gives better readability to the code. But, in your case, there isn't much difference as there are only three cases.
Coming to the more logical(less error), as both implement the same thing, there is no one better than the other in terms of logic.
Hope this helps.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by