While loop enhancements

Forum for suggestions regarding the next update / release of Flowcode

Moderators: Benj, Mods

Post Reply
jmccorison
Posts: 26
Joined: Mon Aug 18, 2008 11:47 pm
Location: Orcas Island, WA
Contact:

While loop enhancements

Post by jmccorison »

It would be most helpful if one could specify a variable to be automatically incremented by the loop processing. In a fantasy world, one would also be able to specify the initial and increment values as well. This would allow for the equivalent C Code for example:

for (i=1;i<=10;++i)

It seems that whenever I'm using the while loop, I'm frequently initializing a variable before hand, incrementing within the loop, and testing it in the while clause. This would certainly make such loops a lot simpler to code.

Jim

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: While loop enhancements

Post by Steve »

Thanks for the suggestion, Jim. I agree that this would help, but if we do too much it might also confuse. One of Flowcode's real assets is that it is simple to use and I want to avoid it becoming too complicated.

If there is a way we could do this and still retain simplicity, then I am very keen to implement it. Perhaps it could be some additional options to the "loop count" option in the loop icon. Something like a tickbox saying "allow access to loop variable". You may also need another construct such as "loop from ____ to ____ by ____" and another option to alter the loop variable at the start or the end of the loop.

As you can see, things can get complicated quite quickly.

Have you got a suggestion to allow this functionality, yet retain simplicity? If anyone else has an opinion on this, please comment.

Mark
Posts: 209
Joined: Thu Oct 19, 2006 11:46 am
Location: Bakewell, UK
Has thanked: 20 times
Been thanked: 16 times
Contact:

Re: While loop enhancements

Post by Mark »

Steve,

Rather than trying to cram more in to the While loop, simplicity can be maintained by adding new loop icons :

For Next Loop
For (Variable auto created in variable list) = {X} to {Y} step {Z}

and for my part a

Do Until Loop (your helpful post on this is clear but as you know when debugging code it is easier the simpler the code).

While on the subject of loops the problem I have most trouble with is exiting loops cleanly, particularly in response to an interrupt that prompts a change in program flow. At the moment I set a flag on interrupt and the while loop tests this flag, making the while loop do two tests (at least) per iteration. Much handier would be an ability to exit the loop (as in Visual Basic).

Best regards,

Mark
Go with the Flow.

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: While loop enhancements

Post by Steve »

Hi Mark,

You could be right - having a separate icon for a "for..next" loop would make sense. Although I think it would make sense to have your "loop until" as an option within the existing loop icon.

And yes, your "exit" requirement could be done, but I can offer you a simpler way - why not just use a connection point to take you outside the loop?

jmccorison
Posts: 26
Joined: Mon Aug 18, 2008 11:47 pm
Location: Orcas Island, WA
Contact:

Re: While loop enhancements

Post by jmccorison »

steve wrote: And yes, your "exit" requirement could be done, but I can offer you a simpler way - why not just use a connection point to take you outside the loop?
Steve,

Ahhh, but that's a GOTO and we've been trained for years that GOTO's are a no-no. :lol:

I understand your concerns about complicating things. (I really want to add a request for a pointer type variable, but boy, talk about complicating things.) I'm afraid that adding multiple icons would do that. It leaves the uninitiated with the question of how they differ and when to use which.

Perhaps adding a additional option in the Loop dialog box titled "Variable Control" or "Advanced Function" or something similar. (BTW, in the dialog box, those should be Radio Buttons, not Check Boxes.) The Variable Control would be subservient to the Loop While option and would only be available if Loop While was selected. Variable Control would have a Check Box which would selected to allow access to its fields. The fields would normally be grayed out showing the defaults of variable=? (maybe "internal"), start=1, increment=1. The options might look something like:

Loop Counter: ______________________ Variables...

Start Value: _____ Increment by: _____

(Of course this then makes the next enhancement suggestion obvious... why can't we have a variable for Start Value and Increment By. It's a slippery slope. :twisted: )

This way you would still have a single icon. The icon would function that same is it currently does. And the learning user would see that there are expanded capabilities which might make them curious and learn about them as their skills grow.

Just my $0.02 worth, which is worth a lot less lately.

-Jim

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: While loop enhancements

Post by Steve »

Hi Jim,

Even with the current exchange rates, that kind of 2 cents is worth a great deal - thanks so much for the input.

You are of course right about the "goto" issue, and it is an easy addition - so I'll probably add a new "Exit Loop" icon in v4 (which implements the "break" C statement).

As for complicating things, it is foremost in my mind to keep things as easy as possible. Although I also want Flowcode to become more powerful for more experienced users. This tradeoff is always difficult to balance, but I do have a plan for this in v4. All will be revealed nearer the time...

Even a pointer data type may eventually be possible. Or at least a VB-like "ByRef" parameter qualifier so that variables (or actually the pointer to the variable) can be passed to user macros and manipulated within them. But I suspect that this is beyond v4.

chevy6600
Flowcode V4 User
Posts: 115
Joined: Fri Feb 22, 2008 6:38 pm
Contact:

Re: While loop enhancements

Post by chevy6600 »

Hi all, i would like to say that all the above comments on making the while loop with enhancements would be a REALY good idea.I too, ended up adding extra program icons and variables to act as counters up to a limit then test to make sure they did not over flow, all of which confused me following my program and could of been better done with the suggestions made in the posts above.
To help keep things beginner friendly i`m in favour of having a radio button in the loop icon which switch`s from beginner to expert mode. Beginner mode having things set up and grayed out, NOT on the whole flowcode sheet but on that particular instance of a loop icon. This i believe would allow learning and a fallback situation.
So count me as another person who would like improvements to the loop icon to be made. :mrgreen:

Post Reply