[solved]Nested For loops

debugging yeilds weird results

Page 1 of 1

3 Replies - 1532 Views - Last Post: 14 September 2009 - 12:07 PM Rate Topic: -----

#1 xtreampb   User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 345
  • Joined: 20-June 07

[solved]Nested For loops

Posted 13 September 2009 - 12:30 PM

hey I am using a few nested for loops and inside each for statment
for(var=val;...;...)

i was using the step and watch features with MSVC++ and i was watching the count var (Located in the 3rd for loop below) and in the watch section said
CXX0017: Error: symbol "count" not found


for(int day=0; day<7; day++)
	{
		for(int ShiftCount=0; ShiftCount < StockShiftVec.size(); ShiftCount++)
		{
			for(int count=0; count < StockShiftVec[ShiftCount].NumEmp; count++)
			{
				if(StockList[count].GetAvailibility(day) && StockList[count].GetStart(day)==StockShiftVec[ShiftCount].ShiftStart && StockList[count].GetWorking(day)==false)
				{
					StockList[count].SetShiftStart(day, StockShiftVec[ShiftCount].ShiftStart);
					StockList[count].SetShiftEnd(day, StockShiftVec[ShiftCount].ShiftEnd);
					StockList[count].SetWorking(day, true);
				}
				
				else if(StockList[count].GetAvailibility(day) && StockList[count].GetStart(day) < StockShiftVec[ShiftCount].ShiftEnd && StockList[count].GetWorking(day)==false)
				{
					StockList[count].SetShiftStart(day, StockList[count].GetStart(day));
					StockList[count].SetShiftEnd(day, StockList[count].GetStart(day) + StockShiftVec[ShiftCount].ShiftLength);
					StockList[count].SetWorking(day, true);
				}
			}//End for(count)
		}//End for(int ShiftCount=0)
	}//End for(int day=0)



shouldn't the var be initilized when the nested for loop is execuited?

Attached File(s)


This post has been edited by xtreampb: 14 September 2009 - 12:08 PM


Is This A Good Question/Topic? 0
  • +

Replies To: [solved]Nested For loops

#2 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: [solved]Nested For loops

Posted 13 September 2009 - 04:28 PM

My guess -- scope. Your break point seems to be on the outer loop -- count is not defined in the outer loop only within the inner loop.

try moving the int count; outside of the loops so that it is in scope at your break point (or move your break point to inside of the loop for count.
Was This Post Helpful? 0
  • +
  • -

#3 poncho4all   User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,422
  • Joined: 15-July 09

Re: [solved]Nested For loops

Posted 13 September 2009 - 04:34 PM

If Nick's guess fails my guess would be that at some point the count is higher than the amount of positions in the array.

What i tried to say was
array[5] and count is 6 so that count will not be found.
Was This Post Helpful? 0
  • +
  • -

#4 xtreampb   User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 345
  • Joined: 20-June 07

Re: [solved]Nested For loops

Posted 14 September 2009 - 12:07 PM

ive tried moving it to before the any of the for loops exicute. Same problem...i think i am going to try it one more time and redefine the watch. also if the count is higher than the size of the vector, the loop should be skiped right?

NVM...The VC++ debugging is eaiser than xCode but somtimes is just a hassel in the features that is uses... sorry people, i am geting it to recognize inside the for loop, thanks for you willing to help.

This post has been edited by xtreampb: 14 September 2009 - 12:08 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1