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.

Author
Message
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 1st Feb 2011 19:34
I would like a separate discussion about this, nothing else. Having used PHP quite a bit I really like elseif. What in DBP can become quite complex code becomes much cleaner using elseif. This example below is not uncommon for me, and here there's no other code to confuse you.



[center]
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 1st Feb 2011 21:07 Edited at: 2nd Feb 2011 18:36
Maybe I'm in a minority but I find the first way easier to follow. It's nicely indented and you can see at a glance what is happening.
It might just be that I'm not used to elseif but it looks wrong.

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 1st Feb 2011 21:33
The problem with following the first example comes when you start adding in a lot of code, like more if nests, while loops and other indented stuff. After a while it becomes hard to track what "level" everything is at. With the elseif command you get everything of the same "level" indented the same. It also is a lot more convenient to write, there are fewer lines of code and less indentations to make.

You could of course break out all the code inside into functions but that makes the code harder to follow as you need to look at multiple places. And more work as you need to come up with function names, make declarations and variables are not in the same scope and needs to be passed etc.

[center]
Fatal Berserker
13
Years of Service
User Offline
Joined: 2nd Jul 2010
Location:
Posted: 2nd Feb 2011 20:16
i prefer else and if to be on the same line, but have a space between them
eg
else if

heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 2nd Feb 2011 20:34 Edited at: 2nd Feb 2011 20:34
When I program in C++ I usually have this setup:

Makes most sense to me

"So hold your head up high and know, it's not the end of the road"
Impulse Game Engine
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 3rd Feb 2011 02:38
C++ doesn't have 'elseif' though, the ability to do 'else' 'if' and have it do the same as 'elseif' is just a result of how the scoping works. But DBPro doesn't have the same rules, so making them separated doesn't make much sense, so I vote for 'elseif'.

Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 3rd Feb 2011 17:50
Yeah, elseif would be consistent with endif.

[b]
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd Feb 2011 18:25
... and consistent with not having spaces in keywords.

Alquerian
18
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 17th Feb 2011 01:24
Maybe I am missing something, but why not use a Switch or Case?
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Feb 2011 14:05
Because switch can't do this:


Alquerian
18
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 17th Feb 2011 16:32 Edited at: 17th Feb 2011 16:40
IanM - Doh! Well, you could do nested switches, but that isn't as elegant. The reason why your example didn't come to mind is that if I am performing comparison checks against different variables, I always have them as separate if statements, even if it is only 1 check. The rest of our development team here is the same way, so I am not very well accustomed to checking the states of multiple variables in a single if/else check.
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 1st Mar 2011 13:51
I like doing multiple if checks so I can add in a single else at the end if none of the above is true. It also means that if something is true then every thing below that is skipped no matter if they are also true or not. I find this useful and use it quite often.

[center]
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 18th Mar 2011 05:01
I am warming to adding ELSEIF as there are a few occasions where it can be handy over the SELECT statement. I have never needed ELSEIF myself, but then I am the master of workarounds

I drink tea, and in my spare time I write software.
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 18th Mar 2011 09:32
Lee:
One of the things I wanted the most when I used to code in DBP

DMXtra
21
Years of Service
User Offline
Joined: 28th Aug 2002
Location: United States
Posted: 18th Mar 2011 11:19
Lee, I vote for adding in elseif it makes so much sense and doesn't need silly workarounds.

Are bandaids ever a good thing?

Dark Basic Pro - The Bedroom Coder's Language of choice for the 21st Century.
Warty
14
Years of Service
User Offline
Joined: 16th Oct 2009
Location:
Posted: 24th Mar 2011 12:16
Certainly hope that this makes it in, I hate how ugly code can look with nested IFs when such a simple extra command (on a user level anyway, can't comment on a developer level) makes life a lot easier. Options are always good!
DMXtra
21
Years of Service
User Offline
Joined: 28th Aug 2002
Location: United States
Posted: 24th Mar 2011 21:06
According to Lee elseif is already in the language:

Source: http://twitter.com/leebambertgc

Quote: "
AGK; The community wanted the ELSEIF command, the community has it. Language now supports this syntax for more robust condition handling.
"


Dark Basic Pro - The Bedroom Coder's Language of choice for the 21st Century.
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 29th Mar 2011 17:52 Edited at: 29th Mar 2011 18:03
Quote: "I have never needed ELSEIF myself, but then I am the master of workarounds "

I have used it in the past on several occasions.
I guess it all boils down to the programmers personal style or preference.

But, it's like Granny said...
"It is better to have it and not need it, than to need it and not have it."

Quote: "AGK; The community wanted the ELSEIF command, the community has it. Language now supports this syntax for more robust condition handling."

Cool beans!

I finally got a chance to play around with an iPhone for a few minutes the other day. (that zoom feature is cool)
So, I am getting more anxious to start developing for these things now that I have had a chance to try it out.
The best thing is that I can take some of my old 2D games that I never got around to making into 3D versions, and re-write the code in AGK.


Iceman
21
Years of Service
User Offline
Joined: 10th Jan 2003
Location:
Posted: 3rd Apr 2011 03:16
Elseif is nice to have, tho I also liked things like OnGosub and others too ;_)
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 7th Apr 2011 05:56
I can confirm ELSEIF is now in:

IF A=1
B=1
ELSEIF A=2
B=3
ELSE
B=5
ENDIF

I drink tea, and in my spare time I write software.
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 11th Apr 2011 16:27
I'm coding an AI for my board game right now and I wish I had elseif in DBP. I could just have it run through a list of possible decisions do the first thing that applies and skip the rest. Now I have to do the same thing without and it just looks messy.

Thurnok
13
Years of Service
User Offline
Joined: 13th Apr 2011
Location:
Posted: 13th Apr 2011 08:48
Sorry I'm late to the game, however, I just joined this forum.

So from reading the thread, am I to assume that DBP does not have a switch/select statement? If it does, I'm curious about IanM's statement regarding what it "cannot" do.

I develop in about 15 different languages (I know.. I'm a junkie!) and many of them if not most of them use the same simple rule that a case's argument must simply evaluate to an integer. So for example, I commonly use something like the following (syntax adjustments needed based on language and switch / select interchangable depending on language):



So was that statement made based on DBP having a switch/select but it simply cannot perform the functionality I depict in the example? Or was that meant as a blanket statement for what a switch/select statement cannot do? Because I'd have to disagree with the latter. ;o)
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Apr 2011 12:53
Your example is what IF...ELSEIF...ELSE...ENDIF is for.

What the select statement is for is checking an expression against a list of constants.


Some languages do allow other expressions to be used instead of constants, but there's not much point in allowing that if you already have the ELSEIF statement.

Login to post a reply

Server time is: 2024-04-20 04:28:48
Your offset time is: 2024-04-20 04:28:48