Thread: Help for some loop count problem..

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    14

    Help for some loop count problem..

    Hi,

    just curious what exactly the "continue", "break" stand for ?
    can some one enlighten me based on the source code below.

    i'm in doubt for understand the source code below.
    Assume that the largest number key in = 14

    y i remove the continue, the value = 13 / 91

    if with continue, answer = 10 /67

    Code:
    
    #include <stdio.h>
    #include <conio.h>
    
    int s,n;
    
    main()
    {
    		int m;
    		int i=0;
    
    		printf("Enter largest number:");
    		scanf("%d",&m);
    		while(1){
    		i++;
    
    		if(i==m) break;
    		if(i%4 ==0) continue;
    		n++;
    		s+=i;
    
    		}
    
    		printf("%d numbers indivisible by 4\n");
    		printf("and less than %d\n\n");
    		printf("Total is %d\n",n,m, s);
    
    
    		getchar();
    		getchar();
    
    		clrscr();
    
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Funny, I would expect that you wouldn't get ANY sensible output at all, since all your arguments to printf is for the last printf, and the first two have no arguments at all...

    continue means "jump to the end of the loop and go on from there" [not "Out of the loop", but just before the loop starts over again at the top].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Continue will jump to the beginning of the loop and break will "break" the loop, cancel it.
    But use proper indentation, please. The code is an eyesore.

  4. #4
    Registered User
    Join Date
    Sep 2007
    Posts
    14
    Quote Originally Posted by matsp View Post
    Funny, I would expect that you wouldn't get ANY sensible output at all, since all your arguments to printf is for the last printf, and the first two have no arguments at all...

    continue means "jump to the end of the loop and go on from there" [not "Out of the loop", but just before the loop starts over again at the top].

    --
    Mats

    Ooopp... sorry+ apologise..

    this is passed year exam question..

    There are OUTPUT with value..

    just wondering what the " continue" and "break " work for the loop....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weired problem in while loop
    By avisik in forum C Programming
    Replies: 14
    Last Post: 12-01-2008, 01:41 PM
  2. Problem with a loop
    By wiggsfly in forum C Programming
    Replies: 5
    Last Post: 11-30-2008, 12:45 PM
  3. whats the problem....
    By vapanchamukhi in forum C Programming
    Replies: 3
    Last Post: 09-05-2008, 12:19 PM
  4. Problem with for loop
    By irsmart in forum C++ Programming
    Replies: 3
    Last Post: 09-29-2006, 04:26 PM
  5. While loop problem
    By nadkingcole in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 06:14 AM