• Post Reply Bookmark Topic Watch Topic
  • New Topic

Else giving error  RSS feed

 
Nathan Tibbitts
Greenhorn
Posts: 11
Eclipse IDE Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing in this code that is getting errors is else.
Why?

 
Henry Wong
author
Sheriff
Posts: 23280
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You forgot to close the "if" block, hence, the "else" can't be matched to an "if".

Henry
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
144
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Proper indentation isn't just "making code look nice", it's a necessary tool to understanding and finding problems with the structure of code.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12529
48
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look VERY carefully at your if statement. it actaully is closed, but not on the line you think. So by the time you get to the else, the compiler says "but there's no if for this to go with..."
 
Nathan Tibbitts
Greenhorn
Posts: 11
Eclipse IDE Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:You forgot to close the "if" block, hence, the "else" can't be matched to an "if".

Henry

I closed the If block using a curly brace. }
It still shows up with an error giving no other token besides syntax error on token "else". delete this token.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
144
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Proper indentation isn't just "making code look nice", it's a necessary tool to understanding and finding problems with the structure of code.

Fix. The. Indentation.
 
Henry Wong
author
Sheriff
Posts: 23280
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You also have a semicolon problem with the "if" block.

Henry
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
144
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:You also have a semicolon problem with the "if" block.

That too.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12529
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nathan Tibbitts wrote:
I closed the If block using a curly brace. }

on this line:

the if-block is closed by that semi-colon. you then have an open curlie that is not associated with the if in any way. It's the exact same this as if you had this:


but even if you take that out, you have problems.  Which is why Bear keeps saying "fix the indentation".  you would have this:




which corrected looks like this:



your if block is NOT properly closed before you hit the else statement.
 
Fred Kleinschmidt
Bartender
Posts: 555
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really need to fix up[ your indentation. Some of your lines are indented 4-spaces, some three, and some 2. Even if you remove the extraneous semicolon and add the proper close for the if-block, you will still have unmatched braces. Indent everything exactly the same number of spaces and you should find the problem.
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you have got the indentation and formatting right: why are you declaring the result as a double? Fibonacci numbers are integers. You can probably use an int, but for results ≥ 2³¹ use longs or BigIntegers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!