Jump to content



Photo
- - - - -

Nested If Statement Syntax Error

if statements nested syntax error

  • Please log in to reply
4 replies to this topic

#1 Sumaxi

Sumaxi

    Newbie

  • Members
  • Pip
  • 4 posts

  • Calculators:
    Fx 9860

Posted 10 September 2014 - 10:39 PM

Haaaai.

 

I've been working on this pretty long program  and not sure why it does not work. I just posted the full version in case you need it, but the smaller little test thing I'm trying to do also doesn't work.

 

Programmed on Casio 9860GII on the actual calculator.

 

When you enter 1 and 1, works. 1,2 works. 1,3 and 2,1 don't work and says syntax error and points toward "Else If (A=2)Ù" and says syntax error.

 

Short Test

Filename:TEST 2
?ãAÙ
?ãBÙ
Ù
If (A=1)Ù
Then "A1"Ù
If (B=1)Ù
Then "B1"Ù
Else If (B=2)Ù
Then "B2"Ù
Else If (B=3)Ù
Then "B3"Ù
IfEndÙ
Else If (A=2)Ù
Then "A2"Ù
IfEnd
Filename:PHYSICS
"PHYSICS PROGRAM"Ù
"RAND"?ãZÙ
"D0"?ãAÙ
"DF"?ãBÙ
"V0"?ãCÙ
"VF"?ãDÙ
"A"?ãEÙ
"T"?ãFÙ
Ù
If (D=Z)Ù
Then Ù
"BIG DOG"Ù
If (B=Z)Ù
Then Ù
A+CF+(1Á2)EF’ãBÙ
Else If (A=Z)Ù
Then Ù
B-CF-(1Á2)EF’ãAÙ
Else If (C=Z)Ù
Then Ù
(B-A-(1Á2)EF’)ÁFãCÙ
Else If (F=Z)Ù
Then Ù
(B-A-(1Á2)EF’)ÁCãFÙ
Else If (E=Z)Ù
Then Ù
(B-A-CF)2ÁF’ãEÙ
IfEndÙ
C+EFãDÙ
Ù
Else If (A=Z Or B=Z)Ù
Then Ù
"LIL PUP"Ù
If (D=Z)Ù
Then Ù
C+EFãDÙ
Else If (C=Z)Ù
Then Ù
D-EFãCÙ
Else If (E=Z)Ù
Then Ù
(D-C)ÁFãEÙ
Else If (F=Z)Ù
Then Ù
(D-C)ÁEãFÙ
IfEndÙ
If (A=Z)Ù
Then Ù
º(D’-C’)Á(2E)+BãAÙ
IfEndÙ
If (B=Z)Ù
Then Ù
(D’-C’)Á(2E)+AãBÙ
IfEndÙ
Ù
Else If (F=Z)Ù
Then Ù
"CAT"Ù
If (D=Z)Ù
Then Ù
Ë(C’+2E(B-A))ãDÙ
Else If (C=Z)Ù
Then Ù
Ë(D’-2E(B-A))ãCÙ
Else If (E=Z)Ù
Then Ù
(D’-C’)Á2(B-A)ãEÙ
Else If (B=Z)Ù
Then Ù
(D’-C’)Á(2E)+AãBÙ
Else If (A=Z)Ù
Then Ù
º(D’-C’)Á(2E)+BãAÙ
IfEndÙ
(D-C)ÁEãFÙ
Ù
Else If (C=Z)Ù
Then Ù
D-EFãCÙ
Else If (E=Z)Ù
Then Ù
(D-C)ÁFãEÙ
IfEndÙ
Ù
"ALL DEF"Ù
Ù
"D0"Ù
AØ
"DF"Ù
BØ
"V0"Ù
CØ
"VF"Ù
DØ
"A"Ù
EØ
"T"Ù
FÙ
"HAPPY BIRTHDAY"Ù

Edited by Sumaxi, 10 September 2014 - 10:46 PM.


#2 TeamFX

TeamFX

    Casio Freak

  • Members
  • PipPipPipPip
  • 117 posts
  • Gender:Male

Posted 11 September 2014 - 06:07 PM

Every 'If' needs an 'IfEnd' and there are quite a few missing in your program.
You can also use the conditional jump command "=>" (Shift + VARS / F3 / F3) as an 'If-Then' replacement.

Instead of writing...
If A=2
Then A+1->A
IfEnd

You write...
A=2=>A+1->A

The conditional jump command does not allow more than one statement to be executed.


Edited by TeamFX, 11 September 2014 - 06:17 PM.

  • MicroPro and shinolife63 like this

#3 Sumaxi

Sumaxi

    Newbie

  • Members
  • Pip
  • 4 posts

  • Calculators:
    Fx 9860

Posted 11 September 2014 - 11:48 PM

Every 'If' needs an 'IfEnd' and there are quite a few missing in your program.
You can also use the conditional jump command "=>" (Shift + VARS / F3 / F3) as an 'If-Then' replacement.

Instead of writing...
If A=2
Then A+1->A
IfEnd

You write...
A=2=>A+1->A

The conditional jump command does not allow more than one statement to be executed.

wait wait wait ...

 

I'm coming from a programming language of higher level...

 

so for EVERY if.

 

So

if a=2

then 2

else if a=3

then 3

else if a=4

then 4

if end

 

 

turns into

if a=2

then 2

ifend

else if a=3

then 3

ifend

else if a=4

then 4

if end

 

 ??



#4 TeamFX

TeamFX

    Casio Freak

  • Members
  • PipPipPipPip
  • 117 posts
  • Gender:Male

Posted 12 September 2014 - 12:36 PM

Every 'If' needs an 'IfEnd', but an 'IfEnd' terminates the 'If' section. So if you have an 'Else', then you have to place it in between the 'If' and its corresponding 'IfEnd'.
 

if a=2
then 2
else if a=3
    then 3
    else if a=4
        then 4
        ifend
    ifend
ifend

Edited by TeamFX, 12 September 2014 - 12:36 PM.

  • flyingfisch likes this

#5 Krtyski

Krtyski

    Casio Addict

  • Members
  • PipPipPip
  • 75 posts
  • Gender:Male
  • Location:Tokyo, Japan
  • Interests:programming, smooth Jazz and 4-wheel driving.

  • Calculators:
    FX-502P, FX-602P, fx-603P, fx-4500PA, 2x fx-5800P, fx-9860GII-2(SH4A) and fx-cg20.

Posted 07 October 2014 - 12:00 PM

Please count how many "If" you use, then put same number of "IfEnd" at proper line (position). Don't think about "Else". Sometime nested If statement without the proper number of "IfEnd" does not give you error massage, be careful. 


Edited by Krtyski, 07 October 2014 - 12:01 PM.

  • flyingfisch likes this





Also tagged with one or more of these keywords: if, statements, nested, syntax, error

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users