• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

semicolon after if{};

 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok got it now.
thanks balaji.
 
Hot dog! An advertiser loves us THIS much:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic