• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

How to skip some looping step in do-while statement

Hi, experts!

In my  CMyView::OnInitialUpdate()
I am reading from text file and populating the data in
ListView line by line:

      // Open the text file we want
      CFile cfFile ("C:\\data.txt", CFile::modeNoTruncate | CFile::modeRead);

      CArchive ar (&cfFile, CArchive::load); // Load its contents into a CArchive

      // Initialise the variable which holds each line's contents
      CString strLine = "";
      if(!ar.ReadString(strLine))
      // Read the first line of the CArchive into the variable
            return; // Failed, so quit out

        int i = 0;


      do // Repeat while there are lines in the file left to process
      {

            if(strLine.GetLength() == 0) // If the line is empty, skip it
                  continue;



            CString strText = strLine; // A line of the file

            // Initialise the variables that will hold the values
            CString str1 = "";
            CString str2 = "";
            CString str3 = "";
            CString str4 = "";
            CString str5 = "";
            CString str6 = "";

            // Extract the first value, and place it in the str1 variable
            AfxExtractSubString(str1, strText, 0, ',');
            // Extract the second value, and place it in the str2 variable
            AfxExtractSubString(str2, strText, 1, ',');
            // Extract the third value, and place it in the str3 variable
            AfxExtractSubString(str3, strText, 2, ',');
            // Extract the second value, and place it in the str4 variable
            AfxExtractSubString(str4, strText, 3, ',');
            // Extract the second value, and place it in the str5 variable
            AfxExtractSubString(str5, strText, 4, ',');
            // Extract the third value, and place it in the str6 variable
            AfxExtractSubString(str6, strText, 5, ',');

            // Do something with these values in the variables



      InsertRow(i, str1, str2, str3, str4, str5, str6);

      i++;

      }while(ar.ReadString(strLine));


The question is how to skip step i = n, where int n is some veriable

Looking forward for your help


0
khlauster
Asked:
khlauster
  • 2
1 Solution
 
SteHCommented:
if (i == n)
   continue;
0
 
AlexFMCommented:
    do // Repeat while there are lines in the file left to process
     {

          if ( i == n )
              continue;
0
 
AlexFMCommented:
Oops...

if (i == n)
{
   i++;
   continue;
}
0
 
khlausterAuthor Commented:
if (i == n)
{
   i++;
   continue;
}

is the right one!

Thank you, AlexFM.

P.S. :
if (i == n)
   continue;

brings only first line out my text file,

Thanks for trying to help me anyway, SteH.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now