File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "elseif" Watch "elseif" New topic


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";
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: 2398
You need a space between the else and if. There is no keyword elseif
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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.


Java API Documentation
The Java Tutorial
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
Thank you.
I agree. Here's the link:
subject: elseif
It's not a secret anymore!