The following exercises let you write your own for loops.
-
Use _ to print only the values of nums
:=[]int{10, 20, 30}. Rewrite the same loop usingslices.Values. Compare the versions. Which one reads more clearly to you? Why? -
Iterate the string "naïve café" with a for-range loop and print the byte index, rune value, and character for each step. How many iterations occur? Which byte indices are skipped? Why?
-
In Java, a do/while loop always iterates exactly once and tests at the end of each iteration:
java
int n;
do { n = read(); process(n); } while (n != 0);
Implement this using Go. An implementation of read and process is provided in the exercises/ex6 directory.
Progress is saved on this device.