Solved

How to skip some looping  step in do-while statement

Posted on 2004-04-28
4
419 Views
Last Modified: 2013-11-20
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
Comment
Question by:khlauster
  • 2
4 Comments
 
LVL 13

Expert Comment

by:SteH
ID: 10940190
if (i == n)
   continue;
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10940191
    do // Repeat while there are lines in the file left to process
     {

          if ( i == n )
              continue;
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 total points
ID: 10940198
Oops...

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

Author Comment

by:khlauster
ID: 10940643
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
while loop over for loop 7 93
countEvens challenge 2 78
sumHeights2  challenge 7 88
Fibonacci challenge 11 110
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now