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

semicolon after if{};  RSS feed

 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
can someone please explain to me the meaning of the following snippet


what I am not clear is what is the significance of the semicolon after the closing curly brace???
what does it imply???
thanks.
 
Bajji Pat
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nikki,

The semicolon has no special significance here, the compiler sees it as just an empty statement.

Bye
Balaji Pattabhiraman
 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply bajji
but still when i put a else statement after the if{}; then it gives me error.
i cannot understand this. does the semicolon signify the end of if statement???
 
Bajji Pat
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nikki,

Ok, as we know that there should be no statements in between if and else statements i.e

if{
}else
{
}

Our case :

if{
}
// This is considered a separate empty statement
;
else{
}// Compiler error

But in this case we have an empty statement (i.e a between if and else(if u choose to use one).
So according to the compiler u have an else statement without an if statement.

Bye
Balaji
 
Niki Nono
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok got it now.
thanks balaji.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!