use case of modulo operator
// given a list of widgets, files, people, etc.
longList = 10000;
feedbackInterval = 100; // to be used as the modulus
// loop over the list to process each item
for( i=1; i <= longList; i++ ) {
// perform some operation
// mod operation gives feedback once every hundred loops
if( i % feedbackInterval == 0 ) {
percentCompleted = ( i / longList ) * 100;
writeOutput( "#percentCompleted# percent complete. " );
}
}
3
1
// array of options that we want to cycle through
weekdays = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri' ];
// option count provides modulus (divisor)
dayCount = weekdays.len();
employeeCount = 14;
// loop over employees while rotating through days
for( i=0; i < employeeCount; i++ ) {
// employee number mod option count
dayIndex = i % dayCount;
// adjust because CFML array indexed from 1
dayIndex++;
// use result to cycle through weekday array positions
weekday = weekdays[ dayIndex ];
writeOutput( "Scheduling employee on #weekday#. " );
}
Thank you!
1
0
0
0
function minutesToHours( m ) {
hours = floor( m/60 );
minutes = m%60;
return "#hours# hours #minutes# minutes";
}
writeOutput( minutesToHours( 349 ) );
Thank you!
0
0
Are there any code examples left?
New code examples in category Other
-
Other 2023-03-27 22:50:10 how to select the whole line in vscode with keyboard shortcut
-
Other 2022-03-27 22:45:24 income of a web developer
-
Other 2022-03-27 22:35:01 \pyrcc_main.py: File does not exist 'resources.qrc'
-
Other 2022-03-27 22:30:45 rick roll embed code
-
Other 2022-03-27 22:20:08 Circuit_04_Potentiometer
-
Other 2022-03-27 22:20:05 iterative power
-
Other 2022-03-27 22:15:11 flutter run all
-
Other 2022-03-27 22:10:05 when is karlson release
-
Other 2022-03-27 22:10:02 wp .htaccess example
-
Other 2022-03-27 22:00:08 bash pause in file read line by line