C++ while loops

convert for loop to whike loops

Page 1 of 1

2 Replies - 1035 Views - Last Post: 21 March 2009 - 08:20 PM Rate Topic: -----

#1 georgehanna1984   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-March 09

C++ while loops

Posted 21 March 2009 - 07:50 PM

hi guys

im trying to convert this code from a 'for' loop to while loop

int row, col, counter = 1, checkCounter = 0;

   for (row=0; row<ROWS; row ++)
   {
	  for (col=0; col<COLS; col++)
	  {
		 if (array[row][col] != counter) checkCounter = 0;
		 counter ++;
	  }
   }
  
   if (checkCounter == 1) return 0;
   else return 1;




Is This A Good Question/Topic? 0
  • +

Replies To: C++ while loops

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Re: C++ while loops

Posted 21 March 2009 - 07:51 PM

View Postgeorgehanna1984, on 21 Mar, 2009 - 08:50 PM, said:

im trying to convert this code from a 'for' loop to while loop

Did you have a question?
Was This Post Helpful? 0
  • +
  • -

#3 matthew180   User is offline

  • D.I.C Head
  • member icon

Reputation: 51
  • View blog
  • Posts: 202
  • Joined: 07-January 09

Re: C++ while loops

Posted 21 March 2009 - 08:20 PM

View Postgeorgehanna1984, on 21 Mar, 2009 - 08:50 PM, said:

hi guys

im trying to convert this code from a 'for' loop to while loop


Why? You won't gain anything. The for() loops are doing a fine job in this situation.

Matthew
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1