Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

elseif

 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need a space between the else and if. There is no keyword elseif
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some languages have an "elif" or "elseif" keyword, but Java just has "if" and "else". You can say

 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic