I wish I had cfnextif
A couple of years ago I did quite a bit of Perl programming. One thing I really liked was syntax like this:
I know we can do a similar thing in ColdFusion like so:
<cfif myVar>
<!--- Do loop stuff --->
</cfif>
</cfloop>
But something like this just seems better, to me at least:
<cfnextif not myVar />
<!--- Do loop stuff --->
</cfloop>
So there's my first CF 9 wishlist item. :)
Jake Munson
34 Yrs old
cfif condition
cfbreak
/cfif
?
Except, as a one-liner?
http://www.chapter31.com/2006/11/29/will-cfmx8-hav...
Yes, just skip to the next iteration of the loop.
@Michael,
It seems that that cfcatch solution is a lot more code than a simple cfif...not sure I see the benefit there.
If you were to expand the sample to use the plain tag sequence and put the loop stuff in as the contents, you essentailly wind up with what we have now using the cfif. I think that if we are going to add multiple ways to do the same thing in the language, the effort would be better spent enhancing cfscript.
It would not (in my humble opinion) make the language better... only bigger with tags that will do the same thing. ColdFusion developers expect a closing tag.. that's the way the language is build.
What about cflocation, cfset, and the many other tags that don't have a closing tag? And XML doesn't always have a closing tag either...that's what the "/>" is for.
You are right about the tags described but those are exceptions on the rule, as in any language. The point in the request above is that adding <cfnextif /> is the same as <cfnextif> </cfnextif> and therefore is the same as the given example that Jack gave us in his first block, or second if you like, of code. I can certainly imagine wanting this if you are used to it coming from a different language but in the case of ColdFusion it's not necessary, because you can already do it in a correct way. If this then do this or else skip to the next.....
I know the difference between "/>" and "</tag>". Believe me, I've been doing web pages for a long time, you don't have to teach me about the basics.
I am illustrating that your logic doesn't hold, because you say "CFML is a Markup Language... XML based.. working with opening and closing tags.", but both CFML and XML have LEGAL ways to both open and close a tag at once, using the />. You said that cflocation and cfset are exceptions to the rule...well what made Allaire decide to "break" this rule? I'd say it was because cflocation and cfset are tags where it doesn't make sense to have a closing tag. I'd submit that <cfnextif /> would be the same thing. I'm just suggesting that such an addition would help in a lot of cases, particularly for folks like me that are used to this syntax.
Oh, and for the record, CFML is NOT XML based. Cold Fusion 1.0 was released before XML even existed:
http://en.wikipedia.org/wiki/Coldfusion#History
http://en.wikipedia.org/wiki/Xml#History
I will not further go into this discussion because it doesn't make sence... you have your point of view.. I have mine, let's leave it at that because we both make strong points.. we just don't agree :-)
<CFLOOP query="qAllSiteLinks">
<CFIF internalLink eq 0>
...
</CFIF>
</CFLOOP>
?