Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / How to nest a if state ment in a case?

Author
Message
Eminent
16
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 21st Oct 2010 04:23
I've been trying to do this but the compiler keeps giving me errors.


Coldfire
17
Years of Service
User Offline
Joined: 22nd Oct 2008
Location: Indiana
Posted: 21st Oct 2010 04:32 Edited at: 21st Oct 2010 04:33
Well, I tried this:


It didn't throw any errors and seemed to work fine. Can you post a sample perhaps?
gbark
20
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 21st Oct 2010 04:33
Works fine for me too.



What version of DBPro are you using? Could be that you need to upgrade. Otherwise, it's probably a different error in your code.
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 21st Oct 2010 04:37
What are you trying to do?

Some code would probably help

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 21st Oct 2010 14:31 Edited at: 21st Oct 2010 14:33
I would guess you were trying to do it like this:


...which would throw an error, whereas:

...would not. At least that's as long as I didn't get my "wotsits" and "thingys" mixed up (as I sometimes do!)

Eminent
16
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 22nd Oct 2010 02:22

Gives me an out of place error.


gbark
20
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 22nd Oct 2010 03:50 Edited at: 22nd Oct 2010 03:52
You can't put the ENDCASE on the same line as your IF. Your code works after moving the commands to separate lines. The reason being how DBPro handles IF statements when you use the THEN keyword (which was similar to the problem is this thread, if you want to take a look) Also, you have if Gas => 10 when I think you need if Gas >= 10

Eminent
16
Years of Service
User Offline
Joined: 15th Jul 2010
Location:
Posted: 22nd Oct 2010 03:52
Thanks man.


baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 22nd Oct 2010 10:30
Quote: "You can't put the ENDCASE on the same line as your IF"

Not true, you can as long as you use an ENDIF. Using THEN means everything after the THEN (even after colons) is counted in the IF statement.



Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 22nd Oct 2010 16:41
Sounds like a syntax parsing bug to me. I can't think of why it would want to work that way?

gbark
20
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 22nd Oct 2010 17:24
Quote: "Not true, you can as long as you use an ENDIF. Using THEN means everything after the THEN (even after colons) is counted in the IF statement."


Yes, you're right about that. I was referring to using the IF-THEN style statement (in which you are forced to separate the lines), rather than IF-ENDIF.

Quote: "Sounds like a syntax parsing bug to me. I can't think of why it would want to work that way?"


Mostly if you have a "short" IF statement that composes of just a few commands in a block. Using the IF-THEN style will cause the rest of the line of code to be associated with that IF block, without you having to explicitly close the block.

So instead of:


You could shorten it to:


It's not an error, it's just a "shortcut". Problem is that it can introduce errors into your code if you aren't aware of it.
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 22nd Oct 2010 19:12 Edited at: 22nd Oct 2010 19:12
Hmm.. I only reserve THEN for use when I have a single condition/action to do, so I guess it's just me.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 24th Oct 2010 11:20
Quote: "Hmm.. I only reserve THEN for use when I have a single condition/action to do, so I guess it's just me."

I very rarely use it for more than one action either...

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Oct 2010 16:18
Quote: "Sounds like a syntax parsing bug to me. I can't think of why it would want to work that way?"

As others have said, that's not so.

Using a THEN is equivalent to adding an ENDIF to the very end of the line.

Your line:


is equivalent to:


You can see that the ENDCASE is in the middle of the IF statements associated code block.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet

Login to post a reply

Server time is: 2026-07-22 03:51:47
Your offset time is: 2026-07-22 03:51:47