String Iteration
String Iteration
Iteration
challenge
Note that you can also use a range-based or enhanced for loop to iterate
over strings. Make sure to cast the iterating variable as char!
While Loop
String iteration is most often done with a for loop. However, a while can be
used as well.
challenge
Above are two ways of iterating through a string. The first way uses the for
loop and the second uses a while loop. Both produces the same result.
However, the for loop is usually preferred because it requires less code to
accomplish the same task. You can also use an enhanced for loop, which
requires the least account of code, but an enhanced while loop does not
exist.
Formative Assessment 1
Formative Assessment 2