3 Replies - 442 Views - Last Post: 17 October 2012 - 03:40 PM Rate Topic: -----

#1 fsdfsdfsd1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 04-October 12

code conversion

Posted 10 October 2012 - 12:29 AM

//vb code
for d=1 to 15+1
//c++ code
for(int d=1;d<15;d++)
//is it right?


Is This A Good Question/Topic? 0
  • +

Replies To: code conversion

#2 DimitriV  Icon User is online

  • >not activating your almonds
  • member icon

Reputation: 555
  • View blog
  • Posts: 2,656
  • Joined: 24-July 11

Re: code conversion

Posted 10 October 2012 - 12:31 AM

Yes, it is.

Just remember, you need to open braces to define the loop body:
for (int d=1; d < 15; d++) {
// code goes within braces
}


Was This Post Helpful? 1
  • +
  • -

#3 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: code conversion

Posted 10 October 2012 - 12:39 AM

I don't think that's right. The condition seems to be different:
In C++ code, d will get a maximum value of 14, before turning to 15 and stepping out of the loop.
In VB code, to my understanding, d would be 16 before it "turns into 17" and steps out of the loop.
So VB code runs 16 iterations compared to C++'s 14 iterations.
To fix it, VB code should be "15-1" instead of "15+1" or C++ code should be "d <= 15+1"
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 571
  • View blog
  • Posts: 2,979
  • Joined: 19-May 09

Re: code conversion

Posted 17 October 2012 - 03:40 PM

I agree with janne.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1