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.

Bug Reports / Problem with "break" and nested for loops

Author
Message
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 4th Nov 2009 22:17 Edited at: 4th Nov 2009 22:20
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.

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.



Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 5th Nov 2009 09:43 Edited at: 5th Nov 2009 09:43
I'm pretty sure the command you want is exit.
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 5th Nov 2009 15:04
@ 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?

Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 5th Nov 2009 16:21
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.
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 5th Nov 2009 17:48
@ Benjamin
Oh, well alright, thanks anyway

<Replaces any breaks in his programs with exit>

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Nov 2009 19:16
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.
C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 8th Nov 2009 23:36
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.

Login to post a reply

Server time is: 2026-06-11 21:23:06
Your offset time is: 2026-06-11 21:23:06