Microsoft Developer Network > Forums Home > Visual Studio Express Editions Forums > Visual C++ Express Edition > Problem with continue statment in for structure in C++ express 2008
Ask a questionAsk a question
 

AnswerProblem with continue statment in for structure in C++ express 2008

  • Monday, November 02, 2009 12:36 AMjuliovarela1 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I am a student of programing and i have a problem with the continue stament in for structure because  i have a example of program but the program nedd display 1,2,3,4,5,6,7,8,9,10
         Used continue to skip printing the value 5
    but only display
    5
    Used continue to skip printing the value 5

    and here the full code please help me..

    #include <iostream>

    using std::cout;
    using std::endl;

    int main()
    {
      int x;

         for ( x=1;x<=10;x++)
       
        continue; //Skip remainding code in loop
                 //only if x is 5
       
        if (x=5)

        cout <<x <<","
       
       
        ;cout<<"\n Used continue to skip printing the value 5"
        <<endl;
           
    ;    return 0
    ;}

Answers

  • Monday, November 02, 2009 1:04 AMWayneAKing Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Your code appears mangled. Do you *really* have the continue
    statement *before* the if statement?

    Also, this:

    if (x=5)

    is an assignment, not a comparison. It sets variable x to 5.

    Use the correct operator: ==

    - Wayne

All Replies