Skip to main content
Article
Mixing and Matching Loop Strategies: By Value or By Index?
SIGCSE '21: Proceedings of the 52nd ACM Technical Symposium on Computer Science Education (2021)
  • Craig S. Miller, DePaul University
  • Amber Settle
Abstract
Increasingly, languages used in computing curricula offer abstract constructs that permit list iteration by value, in addition to the traditional access by index. Given this option, this study explores the loop constructs students choose when solving a problem. We asked students from introductory programming courses to write solutions to two tasks that require iteration through array or list objects, analyzing their responses and noting coding constructs that indicate a loop-by-value strategy or a loop-by-index strategy. Consistent with previous accounts, we find that students may employ a strategy based on their experience and the required task. However, they often implement the strategy using code elements that are inconsistent with the chosen strategy, including referencing the index when a reference to the value at the location of the index is required. Some inconsistencies, such as the use of misleading variable names, do not affect program execution but often coincide with other inconsistencies that produce incorrect code. We recommend that instructors provide explicit scaffolding for the sequential introduction of iterative constructs. We note that a discussion of when each type of loop is typically used may be insufficient and suggest reinforcing habits for maintaining and checking consistency of looping strategies.
Publication Date
March, 2021
DOI
https://doi.org/10.1145/3408877.3432368
Citation Information
Craig S. Miller and Amber Settle. 2021. Mixing and Matching Loop Strategies: By Value or By Index? In Proceedings of the 52nd ACM Technical Symposium on Computer Science Education (SIGCSE '21). Association for Computing Machinery, New York, NY, USA, 1048–1054. DOI:https://doi.org/10.1145/3408877.3432368