For Loop to while loop

A for loop is given, use while loop

Page 1 of 1

1 Replies - 587 Views - Last Post: 05 October 2009 - 06:17 PM Rate Topic: -----

#1 melvinp18  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-October 09

For Loop to while loop

Posted 05 October 2009 - 06:07 PM

A for loop is given below. Use while loop

for (i=0; i<=N; i+=2) {

Sum=Sum + i;

}
Is This A Good Question/Topic? 0
  • +

Replies To: For Loop to while loop

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: For Loop to while loop

Posted 05 October 2009 - 06:17 PM

View Postmelvinp18, on 5 Oct, 2009 - 05:07 PM, said:

A for loop is given below. Use while loop

for (i=0; i<=N; i+=2) {

Sum=Sum + i;

}

There is a rule here :code:
but converting a for into a while is a quickie

int i = 0;
while(i <= N) {
   Sum += i;
   i += 2;
}



My Paypall account is: xxxxx :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1