common code patterns

classic Classic list List threaded Threaded
80 messages Options
1234
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

common code patterns

** Clarence P Martin ** via use-livecode
Hi Folks

I’m looking for a few common code patterns that you find yourselves writing often but aren’t well suited to reusable handlers. So snippets of code or common ways that events are handled together in a script for a certain task.

Cheers

Monte
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode
Do I sense macros?

I have several things that I frequently end up typing that aren't vanilla:

for any structure - repeat/if/case/etc., I normally want the "end" to have
a comment matching the beginning

if i=2 then
   something
end if #i=2

I also frequently use code blocks that I want to label
#<get and parse the file list>
#</get and parse the file list>


There are lots of times where you need to store a property, change it, then
restore it
For just straight code that repeats
put the itemDelimiter into theItemDelimiter
set the itemDelimiter to tab

and then below
set the itemDelimiter to theItemDelimiter


Now with 9, especially, being able to have a command set the result, there
is a lot of
if the result is not empty then exit mouseUp
put it into goop


On Thu, Aug 10, 2017 at 6:01 AM, Monte Goulding via use-livecode <
[hidden email]> wrote:

> Hi Folks
>
> I’m looking for a few common code patterns that you find yourselves
> writing often but aren’t well suited to reusable handlers. So snippets of
> code or common ways that events are handled together in a script for a
> certain task.
>
> Cheers
>
> Monte
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




--
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
On 8/10/2017 6:01 AM, Monte Goulding via use-livecode wrote:
> Hi Folks
>
> I’m looking for a few common code patterns that you find yourselves writing often but aren’t well suited to reusable handlers. So snippets of code or common ways that events are handled together in a script for a certain task.
>
> Cheers
>
> Monte

I am not sure I get exactly what you are looking for, but I find myself
rewriting very similar code over and over again in resizeStack and
resizeControl handlers

on resizeStack x,y
...
-- what I want to do is modify part of an object rect, something like:
-- set rect of btn X to rect of btn X but with new right of y-10
-- and end up writing
set rect of btn X to (item 1 of rect of btn X,item 2 of rect of btn X,
y-10, item 4 of rect of btn X)
...
end resizeStack

Sometimes I just want to add to 1 or more items in the rect, sometime
replace the values. Using top,left,etc, MOVES the object. You have to
use the rect to resize. Of course, I could write functions (and have) to
do this. There are a lot of approaches people take with function, from
general to specific.

set rect of btn X to resizeRectRight(btn X,y-10)

A clean way to do this would be nice. Say something like instead of:
set the right of btn X to y-10 -- moves button
modify the right of btn X to y-10 -- resizes button




_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: common code patterns

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
Monte,

I find that I do this quite often

local tIndex
put 1 into tIndex
repeat for each line tLine in tLines
 add 1 to tIndex
end repeat

What would be very help full is the construct:

repeat for each line tLine in tLines index tIndex
end repeat

This eliminates 3 lines.

Ralph DiMola
IT Director
Evergreen Information Services
[hidden email]


-----Original Message-----
From: use-livecode [mailto:[hidden email]] On Behalf Of Monte Goulding via use-livecode
Sent: Thursday, August 10, 2017 6:01 AM
To: How to use LiveCode
Cc: Monte Goulding
Subject: common code patterns

Hi Folks

I’m looking for a few common code patterns that you find yourselves writing often but aren’t well suited to reusable handlers. So snippets of code or common ways that events are handled together in a script for a certain task.

Cheers

Monte
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode

On Aug 10, 2017, at 10:25 AM, Ralph DiMola via use-livecode <[hidden email]<mailto:[hidden email]>> wrote:

Monte,

I find that I do this quite often

local tIndex
put 1 into tIndex
repeat for each line tLine in tLines
add 1 to tIndex
end repeat

What would be very help full is the construct:

repeat for each line tLine in tLines index tIndex
end repeat

This eliminates 3 lines.


+1. I like this idea because I end of doing something similar a lot. Maybe this sounds a little more x-codish:

repeat for each line tLine in tLines with [counter] tIndex
end repeat

Devin


Devin Asay
Director
Office of Digital Humanities
Brigham Young University

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
How about every time I write a "case" statement inside a switch construct,
the editor adds a blank line and then "break"?

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com



On August 10, 2017 5:03:25 AM Monte Goulding via use-livecode
<[hidden email]> wrote:

> Hi Folks
>
> I’m looking for a few common code patterns that you find yourselves writing
> often but aren’t well suited to reusable handlers. So snippets of code or
> common ways that events are handled together in a script for a certain task.
>
> Cheers
>
> Monte
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode
Ooooh... Ah, but then someone will complain about occassionally having to delete the break.

Bob S


> On Aug 10, 2017, at 10:30 , J. Landman Gay via use-livecode <[hidden email]> wrote:
>
> How about every time I write a "case" statement inside a switch construct, the editor adds a blank line and then "break"?
>
> --
> Jacqueline Landman Gay         |     [hidden email]
> HyperActive Software           |     http://www.hyperactivesw.com


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: common code patterns

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
To make this even more flexible:

repeat for each line tLine in tLines with [counter] tIndex [start] [{1}|x]
[step] [{1}|y]
 
end repeat

Ralph DiMola
IT Director
Evergreen Information Services
[hidden email]


-----Original Message-----
From: use-livecode [mailto:[hidden email]] On Behalf
Of Devin Asay via use-livecode
Sent: Thursday, August 10, 2017 12:33 PM
To: How to use LiveCode
Cc: Devin Asay
Subject: Re: common code patterns


On Aug 10, 2017, at 10:25 AM, Ralph DiMola via use-livecode
<[hidden email]<mailto:[hidden email]>> wrote:

Monte,

I find that I do this quite often

local tIndex
put 1 into tIndex
repeat for each line tLine in tLines
add 1 to tIndex
end repeat

What would be very help full is the construct:

repeat for each line tLine in tLines index tIndex end repeat

This eliminates 3 lines.


+1. I like this idea because I end of doing something similar a lot. Maybe
this sounds a little more x-codish:

repeat for each line tLine in tLines with [counter] tIndex end repeat

Devin


Devin Asay
Director
Office of Digital Humanities
Brigham Young University

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: common code patterns

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
+1

Ralph DiMola
IT Director
Evergreen Information Services
[hidden email]


-----Original Message-----
From: use-livecode [mailto:[hidden email]] On Behalf Of J. Landman Gay via use-livecode
Sent: Thursday, August 10, 2017 1:30 PM
To: How to use LiveCode
Cc: J. Landman Gay
Subject: Re: common code patterns

How about every time I write a "case" statement inside a switch construct, the editor adds a blank line and then "break"?

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com



On August 10, 2017 5:03:25 AM Monte Goulding via use-livecode <[hidden email]> wrote:

> Hi Folks
>
> I’m looking for a few common code patterns that you find yourselves
> writing often but aren’t well suited to reusable handlers. So snippets
> of code or common ways that events are handled together in a script for a certain task.
>
> Cheers
>
> Monte
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode

On Aug 10, 2017, at 11:30 AM, J. Landman Gay via use-livecode <[hidden email]<mailto:[hidden email]>> wrote:

How about every time I write a "case" statement inside a switch construct, the editor adds a blank line and then "break”?



+2! Yes please.

Devin

Devin Asay
Director
Office of Digital Humanities
Brigham Young University

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
On the other hand, it would prevent the common (mostly newbie?) mistake
where you forget to break and the switch statements run amok. I reported a
bug back in the MetaCard days and was gently reminded that I was an idio...
um... in error.

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com



On August 10, 2017 12:39:44 PM Bob Sneidar via use-livecode
<[hidden email]> wrote:

> Ooooh... Ah, but then someone will complain about occassionally having to
> delete the break.
>
> Bob S
>
>
>> On Aug 10, 2017, at 10:30 , J. Landman Gay via use-livecode
>> <[hidden email]> wrote:
>>
>> How about every time I write a "case" statement inside a switch construct,
>> the editor adds a blank line and then "break"?
>>
>> --
>> Jacqueline Landman Gay         |     [hidden email]
>> HyperActive Software           |     http://www.hyperactivesw.com
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: common code patterns

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
Using a break in every case is 95%+ of my switch usage. Also the editor
should not do this if there is a case in the immediately preceding
non-blank/non-comment line. Doing this and J's suggestion would save me lots
of typing.

Ralph DiMola
IT Director
Evergreen Information Services
[hidden email]


-----Original Message-----
From: use-livecode [mailto:[hidden email]] On Behalf
Of Bob Sneidar via use-livecode
Sent: Thursday, August 10, 2017 1:38 PM
To: How to use LiveCode
Cc: Bob Sneidar
Subject: Re: common code patterns

Ooooh... Ah, but then someone will complain about occassionally having to
delete the break.

Bob S


> On Aug 10, 2017, at 10:30 , J. Landman Gay via use-livecode
<[hidden email]> wrote:
>
> How about every time I write a "case" statement inside a switch construct,
the editor adds a blank line and then "break"?
>
> --
> Jacqueline Landman Gay         |     [hidden email]
> HyperActive Software           |     http://www.hyperactivesw.com


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
Switch constructs without breaks are almost like having a 21st century “goto”. You can really make a mess if you try.

> On Aug 10, 2017, at 10:57 AM, J. Landman Gay via use-livecode <[hidden email]> wrote:
>
> On the other hand, it would prevent the common (mostly newbie?) mistake where you forget to break and the switch statements run amok. I reported a bug back in the MetaCard days and was gently reminded that I was an idio... um... in error.



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
FWIW I'm with Jacque on this one.  Not only are exclusive blocks far
more common in practice, they're also explicit - you can see the work
"BREAK" right at the end of the case block.

If a template doesn't include that explicit guidance, I fear for the
experience of new users confused by how their code flows (not to mention
old-timers who either forget to add "BREAK" or wonder why it isn't put
there with the rest of the supplied code).

--
  Richard Gaskin
  Fourth World Systems

J. Landman Gay wrote:

> On the other hand, it would prevent the common (mostly newbie?) mistake
> where you forget to break and the switch statements run amok. I reported a
> bug back in the MetaCard days and was gently reminded that I was an idio...
> um... in error.
>
> --
> Jacqueline Landman Gay         |     jacque at hyperactivesw.com
> HyperActive Software           |     http://www.hyperactivesw.com
>
>
>
> On August 10, 2017 12:39:44 PM Bob Sneidar via use-livecode
> <use-livecode at lists.runrev.com> wrote:
>
>> Ooooh... Ah, but then someone will complain about occassionally having to
>> delete the break.
>>
>> Bob S
>>
>>
>>> On Aug 10, 2017, at 10:30 , J. Landman Gay via use-livecode
>>> <use-livecode at lists.runrev.com> wrote:
>>>
>>> How about every time I write a "case" statement inside a switch construct,
>>> the editor adds a blank line and then "break"?


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode
ick on ralph, and how about if we just get rid of case/switch, and tell
everyone to use if/else if/else/end if

On Thu, Aug 10, 2017 at 2:28 PM, Richard Gaskin via use-livecode <
[hidden email]> wrote:

> FWIW I'm with Jacque on this one.  Not only are exclusive blocks far more
> common in practice, they're also explicit - you can see the work "BREAK"
> right at the end of the case block.
>
> If a template doesn't include that explicit guidance, I fear for the
> experience of new users confused by how their code flows (not to mention
> old-timers who either forget to add "BREAK" or wonder why it isn't put
> there with the rest of the supplied code).
>
> --
>  Richard Gaskin
>  Fourth World Systems
>
> J. Landman Gay wrote:
>
>> On the other hand, it would prevent the common (mostly newbie?) mistake
>> where you forget to break and the switch statements run amok. I reported a
>> bug back in the MetaCard days and was gently reminded that I was an idio...
>> um... in error.
>>
>> --
>> Jacqueline Landman Gay         |     jacque at hyperactivesw.com
>> HyperActive Software           |     http://www.hyperactivesw.com
>>
>>
>>
>> On August 10, 2017 12:39:44 PM Bob Sneidar via use-livecode <use-livecode
>> at lists.runrev.com> wrote:
>>
>> Ooooh... Ah, but then someone will complain about occassionally having to
>>> delete the break.
>>>
>>> Bob S
>>>
>>>
>>> On Aug 10, 2017, at 10:30 , J. Landman Gay via use-livecode
>>>> <use-livecode at lists.runrev.com> wrote:
>>>>
>>>> How about every time I write a "case" statement inside a switch
>>>> construct, the editor adds a blank line and then "break"?
>>>>
>>>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



--
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
On 08/10/2017 10:56 AM, Ralph DiMola via use-livecode wrote:
> Using a break in every case is 95%+ of my switch usage. Also the editor
> should not do this if there is a case in the immediately preceding
> non-blank/non-comment line. Doing this and J's suggestion would save me lots
> of typing.

Agreed. While I rely on the fall-through approach sometimes, it's much
more often that I want break statements. And if I forget to put them in,
it's hard to figure out where the code is breaking.

--
  Mark Wieder
  [hidden email]

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
Hi Monte,

What I do way too often is combining all parameters of a function in a string and then split them up again as needed e.g.:


repeat with i=1 to paramcount()
        if i<paramcount() then
        put param(i)&"," after theValue
         else
            put param(i) after theValue
         end if
end repeat

— specific code follows:

 put item 1 of theValue into isLeft
 put item 2 of theValue into isTop
 put item 3 of theValue into isRight
 put item 4 of theValue into isBottom


As this allows me to pass most variants to the function:

myFunction(10,20,30,40)

Or

myFunction(the rect of grc „myGraphic"
myFunction(the loc of me,10,



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode
In reply to this post by ** Clarence P Martin ** via use-livecode
On 08/10/2017 10:38 AM, Ralph DiMola via use-livecode wrote:
> To make this even more flexible:
>
> repeat for each line tLine in tLines with [counter] tIndex [start] [{1}|x]
> [step] [{1}|y]
>  
> end repeat

I would change the syntax slightly:

repeat for each line tLine in tLines [using tIndex [start [to end]]]
end repeat

but otherwise +1: I end up writing loops like this a lot.

--
  Mark Wieder
  [hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode

> On 11 Aug 2017, at 6:20 am, Mark Wieder via use-livecode <[hidden email]> wrote:
>
> On 08/10/2017 10:38 AM, Ralph DiMola via use-livecode wrote:
>> To make this even more flexible:
>> repeat for each line tLine in tLines with [counter] tIndex [start] [{1}|x]
>> [step] [{1}|y]
>>  end repeat
>
> I would change the syntax slightly:
>
> repeat for each line tLine in tLines [using tIndex [start [to end]]]
> end repeat
>
> but otherwise +1: I end up writing loops like this a lot.

Sorry folks I should have been more specific and said using existing syntax. So the original thing posted is what I’m after at the moment:

local tIndex
put 1 into tIndex
repeat for each line tLine in tLines
   — code
   add 1 to tIndex
end repeat

Jacque the break thing is possible but not what I’m after at the moment. Could you open an enhancement request and I’ll try and get that done for you.

Cheers

Monte
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: common code patterns

** Clarence P Martin ** via use-livecode
Monte Goulding wrote:
 > Sorry folks I should have been more specific and said using existing
 > syntax. So the original thing posted is what I’m after at the moment:
 >
 > local tIndex
 > put 1 into tIndex
 > repeat for each line tLine in tLines
 >    — code
 >    add 1 to tIndex
 > end repeat

Except that's wrong. :)

I tend to use 0 as the initial value, and increment at the top of the loop:

   local tIndex
   put 0 into tIndex
   repeat for each line tLine in tLines
       add 1 to tIndex
       — code
   end repeat

I've found two benefits from this habit:

1. (minor) Clearer distinction between unincremented and incremented
counter.

2. (major) I can "next repeat" at any point in the block and know that
the counter is appropriately updated.

Indeed, it was a runaway loop many years ago that set me know this path.


All this raises a bigger question:  can we for now provide some sparse
minimums and perhaps consider adding more later if truly needed?

Saves work for you folks, and obviates the need to have what would
likely be really long threads here about different coding styles (or
whether all possible styles should be supported in Prefs  - "Damnation
to the dangling 'thens'!" <g>).

--
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  [hidden email]                http://www.FourthWorld.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
1234
Loading...