Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What does this mean?  RSS feed

 
Brian Smith
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i found the following regarding if-else and switch.
An if statement can be used to make decisions based on ranges of values or conditions, whereas a switch statement can make decisions based only on a single integer value.
can you please explain me what does it mean.
thanks.
 
Richard Jensen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Namaste Sathi:
i found the following regarding if-else and switch.
An if statement can be used to make decisions based on ranges of values or conditions, whereas a switch statement can make decisions based only on a single integer value.
can you please explain me what does it mean.
thanks.[/QB]

An if statement allows you to make decisions on boolean expressions. For example:

You cannot directly do the same thing in a switch statement even though you are working with integer values. A similar switch statement might look like:

Now, if you left out the case 19/ case 20 labels, an age of 19 or 20 would doSomethingElse() instead of doSomething().
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!