[PL] How to stop a loop?

Questions about MultiCharts and user contributed studies.
duration
Posts: 179
Joined: 20 Dec 2005
Been thanked: 1 time

[PL] How to stop a loop?

Postby duration » 23 Apr 2010

Hello!

In Powerlanguage, how do you stop a For loop once it has detected something and you don't want the loop to go on as it would waste the computer's time.

For example:

Code: Select all

For value1 = 0 to value1 = 100
begin
value10 = 3 + value10[value1]
if value10 = 30 then value1 = 100 //<------- would this stop the loop?
end;
Many thanks,

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 23 Apr 2010

Yes, that assigning a value to the index of 100 or more will stop the loop in this case, because when it hits the "end" matching the "for" statement, the index will increment from 100 to 101, causing it to be outside of bounds for the loop, causing the loop to be completed.

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Postby ABC » 23 Apr 2010

duration,

either that or you use the "break" statement.

Code: Select all

for Value1 = 0 to 1000 begin
Print("Value1: ", Value1);

if Value1 = 100 then break;
end;
Regards,
ABC

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 23 Apr 2010

Perhaps I answered the question above a bit too literally by just saying "yes that's true". All of these are great ideas and very reasonable suggestions, as alternatives to doing it the way he had inquired about. I agree "break" is probably the most straight forward way to do it, given the circumstance in question and for this particular task that is the approach I would probably use in new code.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 23 Apr 2010

either that or you use the "break" statement.

Gee a break statement. I went searching for "break" and "exit" before and all the help I have did not show it. I guess I should have just tried it (which I did just now and it works). So is there a help kicking around for MC that I am not aware of that has the "break" statement (and other goodies I am not aware of)? I tried the list of unsupported reserve words and it is not there.

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 23 Apr 2010

Break is missing from the help, and doesn't have any hover hints in the editor (though it is color coded correctly as a language keyword). It needs to be added to the help for completeness, and so F1 works on that keyword to pull up something appropriate like it does for "if" etc.

Basically, the only explanation to know it was there was in the release notes:
Version 3.1 of MultiCharts released:
http://www.tssupport.com/support/downloads

FEATURES

Charting
• Updated Hawkeye Add-ons

Programming Language/Script Editor
• 'Switch/case', 'break', 'continue', 'once' keywords implemented

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Postby ABC » 23 Apr 2010

So is there a help kicking around for MC that I am not aware of that has the "break" statement (and other goodies I am not aware of)? I tried the list of unsupported reserve words and it is not there.
bowlesj3,

not that I am aware of. As far as I remember TS introduced "break" into EasyLanguage one or two years ago, about the same time they made "switch" and "case" available for example. TS Support added them to remain the ELD compability, but they are not yet documented in the MC help.
So the TS help will show you some reserved words, that are not yet documented in MC, but do work. And if you find something that doesn't work, TS Support usually includes the functionality into next build once made aware of.
Regards,

Chris

User avatar
RobotMan
Posts: 375
Joined: 12 Jul 2006
Location: Los Altos, California, USA
Has thanked: 31 times
Been thanked: 13 times
Contact:

Postby RobotMan » 23 Apr 2010

Give me a break!
So the TS help will show you some reserved words, that are not yet documented in MC
An undocumented "break" statement?????
That's huge. I can't believe this. All this time and I never knew about that magical word of code in EL/PL. Wow, learned something new.

Do you have to own/subscribe to TS in order to keep up with PowerLanguage? /sarc

Thanks!

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 23 Apr 2010

about the same time they made "switch" and "case" available
Hi Chris,

Are you saying we also have a Case statement? LOL, I use to use a Switch statement somewhere in my 11 or so languages I have programmed in over the years but I can't remember where or even what it does now. I think it was one of the unix shell scripting languages I knew oh so well at one time. Time for a Google search. Maybe I need to do some google searches for MC :-)

John.

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 23 Apr 2010

Yes, there is a switch statement also and it works fine.

It works like:

Switch (switch-expression)
Begin
Case case-expression: statements;
Case case-expression: statements;
Case case-expression: statements;
...
Default: statements;
End;

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 23 Apr 2010

Thanks Bruce,

You are jogging my memory a bit. VB has the "select case" statement where as the switch statement I use to use was very similar to what you show above if I remember correctly. It has been at least 10 years since I have seen it.

John.
Last edited by bowlesj3 on 23 Apr 2010, edited 1 time in total.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 23 Apr 2010

And a clean compile on this one. A nice treat to find out about this.

Code: Select all


variables:
X(0);

if currentbar = 1 then
begin
For X = 1 to 100
begin
if X = 10 then
break;
end;
Print(File("C:\A_ForLoopTest.txt"),
"X=", " " ,
X, " " ,
" ");
switch X
begin
case 1:
Print(File("C:\A_ForLoopTest.txt"),
"case=", " " ,
X, " " ,
" ");

case 2:
Print(File("C:\A_ForLoopTest.txt"),
"case=", " " ,
X, " " ,
" ");
case 10:
Print(File("C:\A_ForLoopTest.txt"),
"case=", " " ,
X, " " ,
" ");
Default:
Print(File("C:\A_ForLoopTest.txt"),
"case Default=", " " ,
X, " " ,
" ");
end;


end; {if currentbar = 1 then}

duration
Posts: 179
Joined: 20 Dec 2005
Been thanked: 1 time

Postby duration » 24 Apr 2010

Thank you all for your reply!
I was looking for something like Break in the help, but could not find it, so I came up with this "if value10 = 30 then value1 = 100" idea.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 24 Apr 2010

I have a couple of loops like that (including the while loops)

Maybe there should be a special thread created for undocumented commands generally (outside of the unsupported reserve word list).

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 24 Apr 2010

Well, and we simply need to remind TSS to add these to the help with search on the forum as a stopgap, as I'm sure we can all agree the peer support forum shouldn't be the primary documentation.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 24 Apr 2010

I have made some loop samples here:


All about loops...
http://forum.tssupport.com/viewtopic.php?t=7351

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 24 Apr 2010

Thanks TJ

Regarding Bruce's comments below,
Well, and we simply need to remind TSS to add these to the help with search on the forum as a stopgap, as I'm sure we can all agree the peer support forum shouldn't be the primary documentation.
I agree however, the undocumented commands thread (and repeat bump references to it for new users) could be the reminder to TSS to update the help. So all that need be done (once a missed command does reach the help) is an update to the thread that it has been added to the help (at the top most likely). So maybe a designated person (maybe TJ for example) keeps a consistent format for this process. For example, maybe the format could include the approximate date the command finally reach the help.

Aonther thing I have noticed (as TJ has done) is that often the forum refrences provide much better examples of the command than the help does. So the thread examples should probably be kept even when the help is updated. It would be nice if the help had some of these better examples included.

One more thing (and maybe TJ has already done this). I have on my todo list the creation of a searchable list of the URLs that I have more than once directed someone to read (especially if it took me more than 2 minutes to find it). It would be mostly to save me time in finding them again in the future (increasing the odds that I will put out the effort). So from now on I will have it in my reminder system to keep updating this reminder with URLs and "search key words" for the URL. I just created it. The reminder title is called "MC forum URL Search Keywords." and in the body of the reminder (or in a searchable document). The first URL I put in is the one TJ just created.
Last edited by bowlesj3 on 24 Apr 2010, edited 2 times in total.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 24 Apr 2010

Hey TJ, you missed the break command in the for loop. 99.9% about loops? I dumped my example in.
I left that out for you... ;-)

.
Last edited by TJ on 24 Apr 2010, edited 2 times in total.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Postby janus » 24 Apr 2010

Well, and we simply need to remind TSS to add these to the help with search on the forum as a stopgap, as I'm sure we can all agree the peer support forum shouldn't be the primary documentation.
Agree on the first and last point but not the second point. I am shocked to find out that I've been ignoring all these undocumented statements. I've always used break, case, etc., in many other languages. This is not acceptable, in fact down right rude and extremely unprofessional by TSS for not documenting all available statements. I've never seen this sort of sloppiness in any other product. TSS MUST fully document them as a priority, as soon as 6.0 is finalized and before any other work is attempted.

:shock: :shock: :shock: :shock: :shock: :shock:

Nick
Posts: 496
Joined: 04 Aug 2006
Has thanked: 4 times
Been thanked: 24 times

Postby Nick » 28 Apr 2010

either that or you use the "break" statement.

Gee a break statement. I went searching for "break" and "exit" before and all the help I have did not show it. I guess I should have just tried it (which I did just now and it works). So is there a help kicking around for MC that I am not aware of that has the "break" statement (and other goodies I am not aware of)? I tried the list of unsupported reserve words and it is not there.
Same. Every now and then I just try things to see if they work (break didn't use too). Full patch notes and updated documentation save users time. (Oh and a comprehensive outstanding bugs database). :D The main reason I don't actively beta test nowadays.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 28 Apr 2010

I agree. I think TSS just does not have enough staff. However I think that after taking that into consideration they are doing an amazing job in spite of it. For my use MC is perfect and if they fix one thing only in MC 6.2 beta (that is the speeds on the replay slider control) then I will have my software for life. But I am a discretionary trader and my needs are not as great.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Postby janus » 28 Apr 2010

Same. Every now and then I just try things to see if they work (break didn't use too). Full patch notes and updated documentation save users time. (Oh and a comprehensive outstanding bugs database). :D The main reason I don't actively beta test nowadays.
Agree all the way Nick; including being a beta tester - I spend too much time as it is debugging my own development work to try and debug someone else's work. If and when I have settled down and stopped developing, then I'll probably join the beta testers for MC provided there is a good two-way communication - in fact I would enjoy it.


Return to “MultiCharts”