Skip to main content
Known Participant
April 8, 2011
Answered

CFLoop Condition

  • April 8, 2011
  • 4 replies
  • 3035 views

For a CFLoop, I want to set the condition so that the loop will run if there is any "step" in the text I am itterating over. I wrote:

<cfloop condition = FindNoCase("step",Code)>

.....

</cfloop>

I am getting an error that says:

Just in time compilation error

Invalid token found on line 45 at position 30. ColdFusion was looking at the following text:"

Whats wrong with what I have done?

    This topic has been closed for replies.
    Correct answer ilssac

    sports_fan72 wrote:

    <cfloop condition = "FindNoCase("/step",Result)">

    ColdFusion is parsing that line like this:  condition = "FindNoCase("   /step   ",Result">

    I.E. The first and second quotes are paired as are the third and forth.  It has no idea what to do with whats in between the second and third.

    You need to alternate your quotes when you need to nest them like that.

    <cfloop condition = "FindNoCase('/step',Result)">

    OR

    <cfloop condition = 'FindNoCase("/step",Result)'>

    4 replies

    Known Participant
    April 8, 2011

    Oh, that makes sense. I thought the quotes would've been nested. Thanks

    Known Participant
    April 8, 2011

    This is my code:

    <cfloop condition = "FindNoCase("/step",Result)">

    The error I recieve says: "

    Just in time compilation error

    Invalid token found on line 38 at position 34.

    ColdFusion was looking at the following text: /s Invalid expression element. The usual cause of this error is a misspelling in the expression text.

    The last successfully parsed CFML construct was a CFLOOP tag occupying document position (38:1) to (38:7).

    ilssac
    ilssacCorrect answer
    Inspiring
    April 8, 2011

    sports_fan72 wrote:

    <cfloop condition = "FindNoCase("/step",Result)">

    ColdFusion is parsing that line like this:  condition = "FindNoCase("   /step   ",Result">

    I.E. The first and second quotes are paired as are the third and forth.  It has no idea what to do with whats in between the second and third.

    You need to alternate your quotes when you need to nest them like that.

    <cfloop condition = "FindNoCase('/step',Result)">

    OR

    <cfloop condition = 'FindNoCase("/step",Result)'>

    Known Participant
    April 8, 2011

    Its still not working. Not sure why. I write:

    <cfloop condition = "FindNoCase("step",Code)">

    and

    <cfloop condition = FindNoCase('step',Code)>.

    Neither works.

    Inspiring
    April 8, 2011

    Since the expression is inside of double quote marks, you need to put hash marks around the function call so that CF knows to evaluate it, otherwise it is just looking at the literal string.  Just like with CFDUMP's var argument.

    Inspiring
    April 8, 2011

    I may be a bit off on that last statement, I just noticed that you don't really specify a condition in your string, just the function call itself. You need to tell CFLOOP what value of the findNoCase() call you want it to look for to exit the loop.

    ilssac
    Inspiring
    April 8, 2011

    The condition parameter of the cfloop tag is expecting a STRING of the command to be checked each loop.

    In other words you need some quotes.

    <cfloop condition = "FindNoCase('step',Code)">

    With your version:

    <cfloop condition = FindNoCase('step',Code)>

    The loop was resolving the FindNoCase function, and expecting the result of that function to be the string that would be the 'Command' to use in each loop.