Tsallaka zuwa abun ciki
Justice Tech School

Loops

for, while and do while repeat code. The range for walks containers.

Example
#include <iostream>

int main() {
  for (int i = 0; i < 3; i++) std::cout << i << " ";
  int n = 3; while (n--) std::cout << "w" << n << " ";
  std::cout << "\n";
  return 0;
}

Result

0 1 2 w2 w1 w0 

Exercise

Range for.

for (int v  a)

Quiz Test

What does range for walk?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.