Answers for "use case modulo, cycling through days"

0

use case modulo, cycling through days

// 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#. " );
}
Posted by: Guest on March-13-2021

Browse Popular Code Answers by Language