Coder's Guild Mailing List

Re: Need help on C++ loop

Posted by Mike McCue on 2001-02-09

The while loop is well above where you're setting the value to 0 again 
(expecting to go back up to the loop).  It won't do it at that point, it 
will continue processing till the end of the file.  Suggestion : possibly 
move the while loop into its own function, and therefor you can call it all 
you want, from wherever you want, but as it is now, it will only run through 
the while loop as it comes down onto the while loop, after its out, it will 
continue to process downward until the code moves the processing elsewhere 
(such as a function)

Hope it helps,
Mike



>From: Zoe <lamtozoe@xxxxx.xxx>
>Reply-To: tcg@xxxx.xx.xx
>To: mccuem1@xxx.xxx
>Subject: Need help on C++ loop
>Date: Fri, 9 Feb 2001 22:58:11 +0100 (MET)
>
>Hi, everyone I am a beginner at C++ and working on a
>file but I just couldn't figure out why I couldn't
>reenter a while loop?
>
>The code is below. The problem works fine at my first
>entry and select one of the listings to be displayed
>in full detail and exit the listing function. But if I
>select to move to the next page, the program should be
>able to exit the while loop and go back to the for
>loop. The listing will be increased by 4 since I want
>the next 4 record in the list. I don't know where went
>wrong. I can't go back in to the while loop? or the
>for loop is not working some how?
>
>Please help.
>Zoe
>
>
>int icount, icountloop;
>int add = 1, list_display, list_max;
>int while_wrong=0, end_for_loop=0, loopcount=0;
>int value=0;
>
>if (num_entries3 > 0) //If there is record, go into
>loop.
>{
>
>icount=num_entries3/NUM_DISPLAYED;//get list loop
>
>if (NUM_DISPLAYED * icount < num_entries3) //add one
>to list loop
>icount = icount + 1;
>
>
>for (icountloop=1; icountloop <= icount; icountloop++)
>{
>list_max = NUM_DISPLAYED * icountloop;
>
>while (while_wrong != 1)
>{
>	loopcount++;
>
>	cout <<"\n\n\t"  <<setiosflags(ios::left)
>	 <<setw(4) <<"  "
>	 <<setw(21) <<"Last Name"
>	 <<setw(17) <<"First Name"
>	 <<setw(15) <<"Phone Numbers\n";
>
>	 for (list_display = add; list_display <= list_max;
>list_display++)
>	{
>	cout <<"\n\t" <<setiosflags(ios::left)
>	 <<setw(1)  <<list_display <<setw(4)<<"."
>	 <<setw(21) <<entry[list_display - 1].last
>	 <<setw(17)<<entry[list_display - 1].first
>	 <<setw(15) <<entry[list_display - 1].phone_num;
>	}
>
>	cout <<"\n\n\tE. Exit to the Main Menu";
>
>	if(icountloop != icount)
>	cout <<"\n\tN. Next Page of Names\n";
>	else
>	if(icountloop == icount) //end of loop inform "no
>more pages"
>	cout <<"\n\tTHIS IS THE LAST PAGE OF NAMES";
>
>	if(value != 0 && loopcount != 1)
>	{
>	  if(add > value && value > list_max && loopcount >
>2)
>	  {
>	    cout <<"\n\tYOU HAVE MADE AN INVALID SELECTION"
>	    <<"\n\tENTER ONE OF THE ABOVE CHOICES";
>	  }
>	}
>
>	value = display_get_num();
>
>
>	if (add <= value && value <= list_max)
>	{
>	  display_select(entry, value);
>	  while_wrong = 1;
>	  end_for_loop=1;
>	}
>	else
>	if (value == 101)
>	{
>	  while_wrong = 1;//exit while loop
>	  end_for_loop= 1;
>	}
>	else
>	if (value == 110)//exit while & goto next page
>listing
>	while_wrong=1;
>}//end while loop
>
>   if(value == 110)//next
>   {
>   add = add + NUM_DISPLAYED; //1+4=5 // 5+4 =9 add 4
>to it
>   while_wrong = 0; //enter loop and reset everything
>for loop control.
>   value = 0;
>   loopcount= 0;
>   }
>
>else
>if(end_for_loop == 1)//exit this function
>{
>  icountloop = icount + 2; //Exit this for loop
>}
>
>}//end for
>}//end if loop
>
>__________________________________________________
>Do You Yahoo!?
>Get personalized email addresses from Yahoo! Mail - only $35
>a year!  http://personal.mail.yahoo.com/
>>
>
>

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com