Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / For / Next loop point

Author
Message
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 6th Jul 2003 20:17
I keep encountering C code as follows:


for (i = 0; i
What do you mean, bears aren't supposed to wear hats and a tie?
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 6th Jul 2003 20:19
Oh lord. Its going to be one of those days. It seems the C squiggly brackets ruined the post above.

Ok the post should have read:

I keep encountering C code as follows:

for (i = 0; i < 5; i ++)
etc.

I assume the object of this is to stop the loop when i = 5.

If this was ported literally to DBP you might end up with
for i = 0 to i < 5
etc.

however, this just means the for/next loop continues forever. Try it and see. So instead, I think the correct DBP code is:

for i = 0 to 5

I am happy to stand corrected though.

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 6th Jul 2003 20:51
I think your example shows variable going from 0 to 4 (not 5).

R Tape loading error
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 7th Jul 2003 18:42
Really? I thought the test was whether the second condition is still true? Even in C?

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Jul 2003 21:41
Yes, but it's testing for less than 5
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 8th Jul 2003 20:27
As I said in my original post. I stand... corrected!

LOL

Still, at least I now know for certain that the correct conversion DBP code is for i = 0 to 5.

Cheers guys

Phil

What do you mean, bears aren't supposed to wear hats and a tie?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Jul 2003 20:48
Argh! No.

The C version will only execute the contents of the loop 5 times (0,1,2,3,4), not 6 times (0,1,2,3,4,5).

The correct version is:

for i = 0 to 4

Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 9th Jul 2003 18:27
IanM, you win another virtual lunch hamper, as officially stolen by me from the park's guests!!

I'm much obliged to you. I keep forgetting the 0 first iteration!

Phil

What do you mean, bears aren't supposed to wear hats and a tie?

Login to post a reply

Server time is: 2024-11-10 13:23:48
Your offset time is: 2024-11-10 13:23:48