Timothy Han wrote:However, it is still not clear to me as when do I use else versus else-if
Timothy Han wrote:Hi Liutauras, thank you for your examples. However, it is still not clear to me as when do I use else versus else-if. Can you elaborate in words further?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
If you have n possibilities, all mutually exclusive, then switch works nicely. If you have ranges, then else if is probably easier to use.Note you should finish with a plain simple else, otherwise the compiler may get confused and think there is a path through the method without assigning grade.Winston Gutkowski wrote:. . . An alternative is the switch statement, . . .
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
"Il y a peu de choses qui me soient impossibles..."
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |