1 / 28

Loops And Lists

Loops And Lists. Seree Chinodom Department of Computer Science. Introduction. Loops - many types List handling. Loop Types. Here is what we will be covering: Index Loops Conditional Loops Looping over a Query Looping over a List Looping over a Structure System

lang
Download Presentation

Loops And Lists

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Loops And Lists Seree Chinodom Department of Computer Science

  2. Introduction • Loops - many types • List handling

  3. Loop Types Here is what we will be covering: • Index Loops • Conditional Loops • Looping over a Query • Looping over a List • Looping over a Structure System • Looping over a COM Collection

  4. 1.1 Index Loops • “FOR NEXT” loop <CFLOOP INDEX="parameter_name" FROM="beginning_value" TO="ending_value" STEP="increment"> • Nesting

  5. 1.2 Conditional Loops • “DO WHILE” loop <CFSET StopIt = 0> <CFLOOP CONDITION="StopIt LESS THAN OR EQUAL TO 5"> <CFSET StopIt = RandRange(1,10)> <HR> </CFLOOP> • Can exit a loop with <CFBREAK>

  6. 1.3 Query Loops • CFQUERY plus <CFLOOP QUERY="GetEmail"> </CFLOOP> • Nesting • more tags inside • Slower

  7. 1.4 List Loops • “FOR EACH” loop <CFLOOP INDEX="ListElement" LIST="#form.state#" DELIMITERS=","> <CFOUTPUT>#ListElement#</CFOUTPUT><BR> </CFLOOP> • Other delimiters

  8. SQL IN clause Form.state = “’MD’, ‘DC’, ‘VA’” SELECT * FROM Customer WHERE State_ID IN (#Form.state#)

  9. List handling • ListAppend, ListPrepend • ListInsertAt • ListSetAt, ListGetAt • ListFirst, ListLast, ListRest • ListDeleteAt • ListFind, ListFindNoCase • ListContains, ListContainsNoCase • ListChangeDelims

  10. List handling Part 2 • ListToArray, ArrayToList • ReplaceList, ListLen • QuotedValueList, ValueList • GetClientVariablesList

  11. 1.5 Structure Loops • “FOR EACH” Loops 2 <CFLOOP COLLECTION=#Departments# ITEM="person"> #person#, #StructFind(Departments, person# </CFLOOP>

  12. 1.6 COM Loops • FOR EACH OBJECT Loops <CFLOOP COLLECTION=#FFUNC# ITEM=file2> <CFOUTPUT> #file2.name# <BR> </CFOUTPUT> </CFLOOP>

  13. ListLen • Returns the number of elements in the list. ListLen(list [, delimiters ]) • ex <CFOUTPUT> #ListLen(“1,2|3,4”, “|”)#<BR> #ListLen(“1,2|3,4”)#<BR> #ListLen(“1,2|3,4”, “,|”)#<BR> </CFOUTPUT>

  14. ListFirst • Returns the first element of the list. • Syntax ListFirst(list [, delimiters ]) • list: List whose first element is being retrieved. • Delimiters: Set of delimiters used in list.

  15. ListLast • Returns the last element of the list. • Syntax ListLast(list [, delimiters ]) • list : List whose last element is being retrieved. • delimiters :Set of delimiters used in list.

  16. ListRest • Returns list without its first element. Returns an empty list (empty string) if list has only one element. • Syntax ListRest(list [, delimiters ]) • list: List whose elements are being retrieved. • delimiters: Set of delimiters used in list.

  17. ListAppend • Returns list with value appended behind its last element. • Syntax ListAppend(list, value [, delimiters ]) • list : Any list. • value: Number or list being appended. • delimiters :Set of delimiters used in list.

  18. ListPrepend • Returns list with value inserted at the first position, shifting all other elements one to the right. • Syntax ListPrepend(list, value [, delimiters ]) • list : Any list. • Value: Number or list being appended. • Delimiters :Set of delimiters used in list.

  19. ListChangeDelims • Returns list with all delimiter characters changed to new_delimiter string. • Syntax ListChangeDelims(list, new_delimiter [, delimiters ]) • list : Any list. • Value: Number or list being appended. • Delimiters :Set of delimiters used in list.

  20. ListGetAt • Returns the element at a given position. • Syntax ListGetAt(list, position [, delimiters ]) • list : List whose element is being retrieved. • Position: Positive integer indicating the position of the element being retrieved. • Delimiters :Set of delimiters used in list.

  21. ListInsertAt • Returns list with value inserted at the specified position. • Syntax ListInsertAt(list, position, value [, delimiters ]) • list : Any list • Position: Position where the value is being inserted. The first position in a list is denoted by the number 1, not 0. • Value :Number or list being inserted. • Delimiters :Set of delimiters used in list.

  22. ListSetAt • Returns list with value assigned to its element at specified position. • Syntax ListSetAt(list, position, value [, delimiters ]) • list : Any list. • Position: Any position. The first position in a list is denoted by the number 1, not 0. • Value : Any value. • Delimiters : Set of delimiters.

  23. ListDeleteAt • Returns list with element deleted at the specified position. • Syntax ListDeleteAt(list, position [, delimiters ]) • list : Any list. • Position: Positive integer indicating the position of the element being deleted. The starting position in a list is denoted by the number 1, not 0. • Delimiters : Set of delimiters used in list.

  24. ListFind • Returns the index of the first occurrence of a value within a list. Returns 0 if no value is found. The search is case-sensitive. • Syntax ListFind(list, value [, delimiters ]) • list: List being searched. • Value : Number or string that is to be found in the items of the list. • Delimiters: Set of delimiters used in the list.

  25. ListFindNoCase • Returns the index of the first occurrence of a value within a list. Returns 0 if no value was found. The search is case-insensitive. • Syntax ListFindNoCase(list, value [, delimiters ]) • list : List being searched. • Value : Number or string being sought among elements of list. • Delimiters : Set of delimiters used in list.

  26. ListContains • Returns the index of the first item that contains the specified substring. The search is case-sensitive. If the substring is not found in any of the list items, it returns zero (0). • Syntax ListContains(list, substring [, delimiters ]) • list: List being searched. • Substring : String being sought in elements of list. • Delimiters: Set of delimiters used in list.

  27. ListContains • Returns the index of the first element of a list that contains the specified substring within elements. The search is case-insensitive. If no element is found, returns 0. • Syntax ListContainsNoCase(list, substring [, delimiters ]) • list: List being searched. • Substring : String being sought in elements of list. • Delimiters: Set of delimiters used in list.

  28. Resource • CFDOCS • Ben Forta Books • cf-talk email list • http://www.houseoffusion.com

More Related