[source code] C Programming Tutorial - 30 - continue

+6 Bucky Roberts · August 7, 2014

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main()
   int num = 1;

       if(num==6 || num==8){
       printf("%d is available \n", num);


   return 0;

Post a Reply


Oldest  Newest  Rating
0 Linguist Llama · January 10, 2016
@Shreyash Gupta

Yes, it works "just fine" without the continue statement (it's not a function)... but does it produce the same output? Perhaps you should compare the two very closely...


You're right; we can do without many of Cs features; in fact, if we're very dedicated we can go back to punch-card programming. Of course we can replace continue with goto end; and write end: at the end of the loop, or invert the condition and swap the logic... The advantage of continue is that it's succinct and idiomatic. It makes the intent easy to understand for a competent programmer who needs to read further into the code.

Does the expression of an infinite loop in a form you don't like render a piece of code invalid? Here, I have removed the loop condition that offends you so much: https://gist.github.com/Sebbyastian/9bf5551f915b2694c77e

P.S. It wasn't a mistake ;)

P.P.S. size_t is not necessarily a typedef for unsigned, though it is required to denote an unsigned integral type.
0 Laura Lee · January 11, 2016
Linguistic Llama, look at the date of my post.
January 3, 2015.

Look at the date of your post.
January 10, 2016

Now about the size_t. size_t is in fact a typedef for unsigned. What does that mean? It denotes an unsigned integral type.
Seeing as you can't post anything original or make sense of anything you copy and paste, with a quick search I found
"size_t. Unsigned integral type. Alias of one of the fundamental unsigned integer types."
From cplusplus.com which is obviously what your source is. 
Why do I say size_t is a typedef? Because each architecture has a special type for the max addressing size. 

P.S. Don't try to make yourself sound smart, you come off as an idiot. 
0 Linguist Llama · January 11, 2016
Would you mind explaining how you think I can "sound smart" when you've never actually heard me make any noises? I encourage you to seek psychiatric help if there are voices in your head, Laura.

I'm aware of the differences in dates. You were responding to me in that message; notice there are traces of the infinite loop you complained about in the revision logs < https://gist.github.com/Sebbyastian/9bf5551f915b2694c77e/revisions >?

I figured it's better to respond later rather than never. It's unfortunate that account was banned before I got an opportunity to respond... Wow, we've known each other for some time, huh?!

I don't use cplusplus.com as a resource; you should know me better by now. Either you came to that conclusion with so much information to the contrary or you forgot so much information and you came to that conclusion with so little actual recalled information... Either way, I feel sorry for you and I think it might be a good idea to do a little more research before you come to conclusions.

You seem to be implying that you're concerned about the validity of cplusplus.coms statement. I can't say I blame you; cplusplus.com isn't the authoritative document defining C. Having said that, cplusplus.com doesn't seem to be wrong about this; `size_t` needn't be declared using typedef, let alone `typedef unsigned size_t;`... I encourage you to put your money where your mouth is and find a nice reference to cite.

If you're looking for something with authoritative validity, the only authority in this case is the ISO/IEC committee JTC1/SC22/WG14. You can find the free, unabridged standard draft that most closely reflects their commercial publication of the standard document by performing a Google search for  "n1570.pdf". Note that this document outlines C11, which is C in this day and age according to ANSI and ISO/IEC. If you're looking for C99, that search would be "1256.pdf" or "ansi.c.txt" for C89, though keep in mind there are outdated aspects of these older documents.

Can you find me anywhere within the C89, C99 or C11 standards/standard drafts that specifically requires that size_t be a typedef?

I should also hope that you'll find me a citation from that standard proving your previous claim that introducing non-portable aspects (such as using int to store the return value of strlen) will result in more optimal code. Alas, you won't.

You might have gathered that I'm quite familiar with the C standard documents. If you need help finding citations I can recommend that you to visit Freenodes ##C chatroom; you might need a registered nickname to do so. Be aware, however, that the regulars there are quite unlikely to treat you with dignity when you repeatedly insist upon using personal experience or mere guesswork to accredit your claims.
0 Shreyash Gupta · January 3, 2015
Admin Bucky,
This program works fine with or without the continue function. Can you please give me another example with continue function?
0 Laura Lee · January 3, 2015
Shreyash you really don't need continue in this scenario. In fact, of eight years programming in C I can not think of a single moment where continue has been useful to me. I have always managed to find a way around it.
0 Laura Lee · January 4, 2015
Well your code is already broken.
size_t size = 0;
    while (size >= 0)

size_t is a typedef for unsigned, therefor you'll never actually have size to less than zero.

Once you give me a working piece of code then I'll glady replace the continue for you.
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator