This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes elseif Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "elseif" Watch "elseif" New topic
Author

elseif

Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
I remember seeing an "elseif" statement in a program somewhere so I tried something like this:

int x;
String y;
if (x == 1){
y = "one";
}elseif(x == 2){
y = "two";
}else{
y = "neither one nor two";
}

It wouldn't compile. Maybe I'm using the wrong syntax or something. What is the correct syntax for elseif?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You need a space between the else and if. There is no keyword elseif
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Some languages have an "elif" or "elseif" keyword, but Java just has "if" and "else". You can say



[Jess in Action][AskingGoodQuestions]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
For future reference, it will help a lot if you post the compiler error you get. Most of the time, the error message includes critical information we need in order to answer your question.

I hope the above comments answer your question.

Layne


Java API Documentation
The Java Tutorial
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: elseif