C/Language Basics/For Continue

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Count spaces in string: how to use continue

#include <stdio.h>
int main(void)
{
  char s[80], *str;
  int space;
  printf("Enter a string: ");
  gets(s);
  str = s; 
  for(space = 0; *str; str++) {
    if(*str != " ") 
        continue;
    space++;
  }
  printf("%d spaces\n", space);
  return 0;
}


For loop with continue

  
#include <stdio.h>
int main(void) {
  int x;
  for( x = 0; x < 100; x++ ) {
      printf("Before continue.");
      continue;
      printf("%d ", x); /* this is never executed */
  }
  return 0;
}