Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CFLoop Condition

New Here ,
Apr 08, 2011 Apr 08, 2011

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?

2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Apr 08, 2011 Apr 08, 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)'>

Translate
Valorous Hero ,
Apr 08, 2011 Apr 08, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 08, 2011 Apr 08, 2011

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

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

and

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

Neither works.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 08, 2011 Apr 08, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 08, 2011 Apr 08, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 08, 2011 Apr 08, 2011

Reed Powell wrote:

Since the expression is inside of double quote marks, you need to put hash marks around the function

NO YOU DON'T.  <cfloop condition...> is a bit of odd duck.  You don't put a function or expression.  You put a string that represents the function or expression you want evaluated each loop itteration.  It is somewhat like an evaluate() string.

For example, from the docs.

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_j-l_12.html

<cfloop condition = "CountVar LESS THAN OR EQUAL TO 5">

You will note that the condition is in quotes, but there are NO hash|pound|number|othotrope|# characters used.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 08, 2011 Apr 08, 2011

HOW is it not working?  Errors, incorrect results, what are you seeing that we need to know to guide you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 08, 2011 Apr 08, 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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 08, 2011 Apr 08, 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)'>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 08, 2011 Apr 08, 2011
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources