Hacker News new | past | comments | ask | show | jobs | submit login

Not OP but I'm teaching undergrad C. I'm assuming you have covered while loops before hand, if not, start there and cover the constructs with them that you would normally use a for loop for, example:

  int i = 0; //a
   
  while(i < 10) //b
  {
      printf("%d\n"); //c
      ++i; //d
  }
and introduce for loops as a special case of the while loop:

      //a        //b     //d
  for(int i = 0; i < 10; ++i)
  {
      printf("%d\n",i); //c
  }
Then outline situations when you would use a for loop over a while loop, fixed number of repetitions, use with arrays etc.



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: