Find the number from 100 to 200 that is not divisible by 3 and output it, and explain the difference between continue and break

Ideas

100-200 means that the cycle is required and cannot be divisible by 3, that is, the remainder of 3 is not equal to 0.
Method 1

#include<stdio.h>
int main()
{
    
    
 int i;
 for(i = 100;i<=200;i++)
 {
    
    
  if(i%3==0)
  {
    
    
   continue;
  }
  printf("%d",i);
 }
 return 0;
}

Method 2

#include<stdio.h>
int main()
{
    
    
 int i;
 for(i = 100;i<=200;i++)
 {
    
    
  if(i%3!=0)
  {
    
    
   printf("%d  ",i);
  }
 }
 return 0;
}

Output result
Both methods have the same result
Replace the continue in method 1 with break

#include<stdio.h>
int main()
{
    
    
 int n;
 for(n = 100;n<=200;n++)
 {
    
    
  if(n%3==0)
  {
    
    
   break;
  }
  printf("%d  ",n);
 }
 return 0;
}

The output result is incomplete at this time
The difference between continue and break
continue ends this (this trip) loop
break ends the entire loop

Guess you like

Origin blog.csdn.net/weixin_45824959/article/details/105064368