notexOPENOverview
Notex/Languages/Practice: for loops
02.14LESSON 14 OF 19 · 1 MIN READ

Practice: for loops

Always free to read

The following exercises let you write your own for loops.

  1. Use _ to print only the values of nums := []int{10, 20, 30}. Rewrite the same loop using slices.Values. Compare the versions. Which one reads more clearly to you? Why?

  2. 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?

  3. 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.
KEEP EXPLORING

One note leads to another.

Back to the library →
⌕
Search across the entire library ⌘ K