Thread: Problem with continue;

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    70

    Problem with continue;

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        for(double lusindex = 5; lusindex <= -4; lusindex--)
        {
                   if(lusindex=0) continue;
                   cout<< "1/" <<lusindex<<" = "<<1/lusindex<<endl;
                   
                   
                   }
        cin.get();
    }
    no warnings.
    and it isn't couting something , it just shows blackscreen
    Last edited by hallo007; 10-29-2006 at 10:55 AM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> for(double lusindex = 5; lusindex <= 4; lusindex--)
    Your problem is in there.

    >> if(lusindex=0) continue;
    And this is wrong as well.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The problem isn't with continue, it's that all your numbers and conditions make absolutely no sense. The loop never runs, and if it did, it would run forever. The equality operator is ==, not =.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    so i got this now
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        for(double lusindex = 5; lusindex <= -4; lusindex--)
        {
                   if(lusindex==0) continue;
                   cout<< "1/" <<lusindex<<" = "<<1/lusindex<<endl;
                   
                   
                   }
        cin.get();
    }
    how do i let the loop run?

  5. #5
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    What do you expect the output to be?
    Here is another example using continue that will skip the number 5

    Code:
    for ( int i = 0; i < 10; i++ )
    {
       if ( i == 5 )
          continue;
    }

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > double lusindex = 5; lusindex <= -4;
    This starts off by being false, so nothing happens.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    how can you make it TRUE without chanching the numbers??

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >how can you make it TRUE without chanching the numbers??
    Define your own reality where the rules of mathematics no longer apply.
    My best code is written with the delete key.

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    lol , oke its not possible

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    i found it , it was very , very very stupid:s
    i writed lusindex <=-10 and it has to be >=
    lol

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Define your own reality where the rules of mathematics no longer apply.
    Ah, you mean accountancy
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Ah, you mean accountancy
    I was thinking statistics, but same diff.
    My best code is written with the delete key.

  13. #13
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Code:
    #include <stdio.h>
     
    int main(void){
        int count, r_num[7], found, n;
        srand (time(0));
        for(count=0; count<7; count++){
            do{
                found=0;
                r_num[count] = rand()%45+1;
                for(n=0;n<count;n++){
                    if(r_num[n]==r_num[count]){
    	            found=1;
                        break;
        	        }
                }
            } while(found==1);
        }
        printf("%i %i %i %i %i %i %i",r_num[0],r_num[1],r_num[2],r_num[3],r_num[4],r_num[5],r_num[6]);
        fgetc(stdin);
        return 0;
    }
    Try lowering 45. The numbers will always be different, if you make 45 smaller than 7, the program never finishes the loop, because it hopes to find unused numbers in that range
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. Recursion Problem I think
    By clearrtc in forum C Programming
    Replies: 4
    Last Post: 07-31-2006, 07:10 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM