The difference between the continue in the while and the continue in the IF

Source: Internet
Author: User
#include <stdio.h>
int main ()
{
	int n;
	for (n=100;n<=200;n++)
	{
if (n%3==0)
		continue;
	printf ("%d", n);
	}
	printf ("\ n");
	return 0;
}
The number of outputs from 100 to 200 that cannot be divisible by 3   

#include <stdio.h>
int main ()
{
	int n;
	for (n=100;n<=200;n++)
	{
		while (n%3==0) {
			continue;}
		printf ("%d", n);
	}
	printf ("\ n");
	return 0;
} Outputs 100 to 200 cannot be divisible by 3 number of the   

first program seventh line with the IF statement the  second program seventh line with a while statement with the
first program can output 100 to 200 of all the number     can not be divisible by 3 But with the second one can only output 100 101 then no, why.


Continue is only responsible for having a loop statement produce a "jump back", which is the innermost loop statement closest to continue.

Your first continue is for (n=100;n<=200;n++) (because if is not a loop statement, continue will not find it)

Your second continue is the while (n%3==0) loop, because this is the closest inner loop to the continue.

1 2 while (n%3==0) {continue;}//When n=102, this while will loop indefinitely, freezing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.