User Guide

Table Of Contents
624 Chapter 26: Introduction to Retrieving and Formatting Data
Example: using the cfloop tag and Rand function
The following example uses the cfloop tag and the Rand random number generating function to
artificially delay the generation of data for display. It simulates a situation in which it takes time to
retrieve the first data and additional information becomes available slowly.
<html>
<head>
<title>Your Magic numbers</title>
</head>
<body>
<h1>Your Magic numbers</h1>
<P>It will take us a little while to calculate your ten magic numbers.
It takes a lot of work to find numbers that truly fit your personality.
So relax for a minute or so while we do the hard work for you.</P>
<h2>We are sure you will agree it was worth the short wait!</h2>
<cfflush>
<cfflush interval=10>
<!--- Delay Loop to make is seem harder. --->
<cfloop index="randomindex" from="1" to="200000" step="1">
<cfset random=rand()>
</cfloop>
<!--- Now slowly output 10 random numbers. --->
<cfloop index="Myindex" from="1" to="10" step="1">
<cfloop index="randomindex" from="1" to="100000" step="1">
<cfset random=rand()>
</cfloop>
<cfoutput>
Magic number #Myindex# is:&nbsp;&nbsp;#RandRange(
100000, 999999)#<br><br>
</cfoutput>
</cfloop>
</body>
</html>
Reviewing the code
The following table describes the code and its function:
Code Description
<h2>We are sure you will agree it was
worth the short wait!</h2>
<cfflush>
Sends the HTML header and all HTML output to
the
cfflush tag to the user. This displays the
explanatory paragraph and H2 tag contents.
<cfflush interval=10>
Flushes additional data to the user whenever at least
10 bytes are available.