Quantcast
Viewing latest article 3
Browse Latest Browse All 25

Loops: Lesson - Continuing in C

Hello,

In the lesson: https://www.codecademy.com/courses/learn-c/lessons/loops-c/exercises/continuing

The first part of the exercise says to:
Use continue to make the while loop skip the print statement for when i == 5.

I did it like this:

#include <stdio.h>

int main() {
  int i = 0;
  while(i < 10) {
    // Figure out how to skip the print of 5 here
    i++;
    if (i == 5) {
      continue;
    }

    printf("%d\n", i);
  }
}

and it prints from 1-10 excluding 5 but it should have been 0-9 excluding 5.
can someone guide me as to what I am missing here?

2 posts - 2 participants

Read full topic


Viewing latest article 3
Browse Latest Browse All 25

Trending Articles