Skip to content

Instantly share code, notes, and snippets.

@ryanguill
Forked from anonymous/fizzbuzz.cfm
Created July 19, 2012 13:20
Show Gist options
  • Save ryanguill/3143875 to your computer and use it in GitHub Desktop.
Save ryanguill/3143875 to your computer and use it in GitHub Desktop.
Fizz Buzz
<!--- cf function that solves the fizzbuzz test --->
<!--- I generally don't like functions outputing themselves,
I would rather have it do a return - gives you more flexability later --->
<cffunction name="displayFBMsg" access="private" hint="whatever..."><!--- no returntype / no output --->
<cfargument name="numberOfIterations" required="true" type="numeric"><!--- personal preference, I like name, type, required, but thats not a big deal --->
<cfloop from="1" to="#arguments.numberOfIterations#" index="i"><!--- i is not var'd --->
<!--- with this logic, you're going to do at least 2 checks on every number,
and if those pass, you'll do 4, regardless (just as a comparison) --->
<cfif i MOD 3 EQ 0 OR i MOD 5 EQ 0>
<cfif i MOD 3 EQ 0>fizz</cfif><cfif i MOD 5 EQ 0>buzz</cfif>
<cfelse>
<cfoutput>#i#</cfoutput>
</cfif>
</br>
</cfloop>
</cffunction>
<!--- call the function --->
<cfoutput>#displayFBMsg(100)#</cfoutput><!--- I like that you parametized the number of iterations --->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment