2 Replies - 201 Views - Last Post: 05 October 2012 - 01:12 PM Rate Topic: -----

#1 fsdfsdfsd1  Icon User is offline

  • New D.I.C Head

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

doubt in basic code for loop

Posted 05 October 2012 - 01:53 AM

for i=0 To height - 1
for i=0 To height



//is it correct
//c++

for(i=0;i<height;i++)


for(i=0;i<=height;i++)


Is This A Good Question/Topic? 0
  • +

Replies To: doubt in basic code for loop

#2 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,165
  • Joined: 08-January 12

Re: doubt in basic code for loop

Posted 05 October 2012 - 01:54 AM

Yup, these are correct.
Was This Post Helpful? 0
  • +
  • -

#3 Duta  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 43
  • Joined: 21-June 12

Re: doubt in basic code for loop

Posted 05 October 2012 - 01:12 PM

As long as i is already defined, otherwise you need this:
for(int i = 0; i < height; i++) { /* Code to execute */ }


instead of
for(i = 0; i < height; i++) { /* Code to execute */ }


Otherwise the compiler will give you an error, basically saying that it doesn't know what i is, as you haven't defined it.
So this is correct (as you've defined i before entering the loop):
int i;
for(i = 0; i < height; i++) { /* Code to execute */ }


This post has been edited by Duta: 05 October 2012 - 01:13 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1