The Game Creators
The Game Creators Home Online Shop Click to Login
  Hot: Christmas CompetitionNovember NewsletterModel Pack 36DB Pro Pack 2009DGS BonanzaCharacter PackFPS Creator Bonanza;
The Game Creators
Bug Reports / Problem with "break" and nested for loops
[ Filter Bugs: Confirmed, Fixed, Rejected, Scheduled, Pending ]

Go to the first page of this board Return to the Forum Menu Post Message
7 Messages - Page   of 1   
Bookmark and Share Search the Forum

Author Message
C0wbox

User


Joined: Tue Jun 6th 2006
Location: 0,125,-250
Posted: 4th Nov 2009 15:17     Edited: 4th Nov 2009 15:20     | link | toggle

Where INDEX2-1 is the last entry into the array TREES and we start with TREES.ACTIVE from 0 to INDEX2-1 all equal to 1.
+ Code Snippet
for something_unrelated=0 to something_else
 if one_parameter=true

  for TINDEX=0 to INDEX2-1
   if TREES(TINDEX).ACTIVE=1
    TREES(TINDEX).ACTIVE=0
    break
   endif
  next TINDEX

 endif
next something_unrelated

The problem is that where it should find the first 1 in the array and replace it with 0, it locates them all and replaces them all with 0 because it never breaks from the loop. I know this to be true because when the main outer for-loop is run once and there are say, 150 TREES entries, all the TREES().ACTIVEs are changed to 0.

This isn't the first place I've encountered this problem. But with this project it is more of a nuisance than where I first encountered it.

For the time being I have had to make do with a while-loop, which works, but I'm not very happy about using.

+ Code Snippet
for something_unrelated=0 to something_else
 if one_parameter=true

  while TINDEX<INDEX2-1
   inc TINDEX
   if TREES(TINDEX).ACTIVE=1
    TREES(TINDEX).ACTIVE=0
    exit
   endif
  endwhile

 endif
next something_unrelated


Back to top
Soharix
Report this message as abusive
Benjamin

User


Joined: Sun Nov 24th 2002
Location: France
Posted: 5th Nov 2009 02:43     Edited: 5th Nov 2009 02:43     | link | toggle

I'm pretty sure the command you want is exit.
Back to top
Report this message as abusive
C0wbox

User


Joined: Tue Jun 6th 2006
Location: 0,125,-250
Posted: 5th Nov 2009 08:04           | link | toggle

@ Benjamin
I thought exit only worked for do-loops, repeat-loops and while-loops?

If exit is what I need, what does break actually do?

Back to top
Soharix
Report this message as abusive
Google Ad
Back to top
 
Benjamin

User


Joined: Sun Nov 24th 2002
Location: France
Posted: 5th Nov 2009 09:21           | link | toggle

I think it breaks to the debugger however I don't have the documentation in front of me so I can't see right now.
Back to top
Report this message as abusive
C0wbox

User


Joined: Tue Jun 6th 2006
Location: 0,125,-250
Posted: 5th Nov 2009 10:48           | link | toggle

@ Benjamin
Oh, well alright, thanks anyway

<Replaces any breaks in his programs with exit>

Back to top
Soharix
Report this message as abusive
Green Gandalf

Valued Member


Joined: Mon Jan 3rd 2005
Location: Cornwall UK
Posted: 7th Nov 2009 12:16           | link | toggle

COwbox

Quote: "I thought exit only worked for do-loops, repeat-loops and while-loops?"

I sympathise with you. This is what the Help file says:

Quote: "Only control loops that have an uncertain exit condition can use this command such as DO LOOP, WHILE and REPEAT loops. EXIT will have no effect on GOTO loops during the running of your program."

I wasn't aware the DO LOOP had any built-in exit condition uncertain or otherwise.

I, like you, would have assumed that the Help file means that you can't use exit from a for next loop (which usually doesn't have an uncertain end condition from the programmer's point of view) and often make the same mistake till I remember. You can use exit of course.

I really think someone should write those files in plain English - or German, French, Chinese, etc. We all have access to Google translator after all. Just one standard language would be enough.
Back to top
Report this message as abusive
C0wbox

User


Joined: Tue Jun 6th 2006
Location: 0,125,-250
Posted: 8th Nov 2009 16:36           | link | toggle

Na my main problem was simply caused by the fact C++ uses break to exit for-loops. I assumed languages as old as BASIC and C would both use the same command for something this simple.

Back to top
Soharix
Report this message as abusive

Go to the first page of this board Return to the Forum Menu Post Message
7 Messages - Page   of 1   
Search the Forum

You must be logged-in to post messages to this forum. You can register an account for free. Or click here to login.
Forum Search

Enter a word or phrase to search our Forum for:

Thread Subject Search
Search Phrase:
Search Scope: Entire forum
Just this board
 
Google Forum Search
Search Phrase:
 
Apollo v2.02


Dark Game Studio
Privacy Policy AUP Top of Page