Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created September 10, 2024 14:07
Show Gist options
  • Save bennadel/0d02b5680c506fae56b9b77a49810441 to your computer and use it in GitHub Desktop.
Save bennadel/0d02b5680c506fae56b9b77a49810441 to your computer and use it in GitHub Desktop.
Dynamically Define For-Loop Increment In ColdFusion
<!--- ColdFusion mechanics. --->
<cfscript>
(() => {
var fromAscii = asc( "a" );
var toAscii = asc( "z" );
for ( var i = fromAscii ; i <= toAscii ; i += step /* VARIABLE */ ) {
echo( chr( i ) & " " );
// Randomly define the next for-loop increment.
// --
// Note: the step variable is hoisted to the top of the Function and is
// available for consumption in the for-loop mechanics. This is a feature of
// the language, not a bug. Hosting is aces!
var step = randRange( 1, 8 );
}
})();
</cfscript>
<!--- JavaScript mechanics. --->
<script type="text/javascript">
(() => {
var fromAscii = "a".charCodeAt();
var toAscii = "z".charCodeAt();
for ( var i = fromAscii ; i <= toAscii ; i += step /* VARIABLE */ ) {
console.log( String.fromCharCode( i ) );
var step = ( 1 + Math.floor( Math.random() * 8 ) );
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment