June 25, 2024, 05:40:03 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


EACH command and ++

Started by Andy, December 03, 2015, 12:59:56 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

December 03, 2015, 12:59:56 AM Last Edit: December 03, 2015, 01:03:02 AM by andy1966
Hi,

Whilst looking at some code to read an excel file, I came across the EACH command, It's a command I have never used before and the help file does not shed any light on it for me.

IF pTables <> NULL
FOR temp = EACH pTables as STRING
PRINT "Sheet name - ",#temp
PRINT "Cardinality:",dbCardinality(pDB,#temp)
PRINT "\tColumns:"
pColumns = dbListColumns(pDB,#temp)

IF pColumns <> NULL
FOR temp2 = EACH pColumns as STRING
PRINT "\t\tColumn name:",#temp2
NEXT
ListRemoveAll(pColumns,TRUE)
ENDIF
NEXT
ListRemoveAll(pTables,TRUE)
ELSE
PRINT "Unable to list tables"
ENDIF


I presume EACH means something like
FOR temp2 = 1 to (say 10) or FOR temp2 = 0 to 9?

I also noticed that the NEXT does not have NEXT temp2.


Another little question:
I know A += 1 adds one to A, but what does A ++ do? - it looks like they mean the same thing...
Been meaning to ask this little one for some time.

Thanks,
Andy.
:)

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

A++ means increment A by 1 - instead of typing A=A+1

Brian

LarryMc

Brian's correct
the following lines of code accomplish the same thing
A = A + 1
A += 1
A++


as does
A = A - 1
A -= 1
A--


As for FOR/EACH loops
look first at the Language>Loop Statements > For / Each Statement section of the help file which takes you to the
Using Linked List section. Refer to the Iterating the List sub-section.

From comparing the 'simple' form in the help file with example code you posted it should be evident that the dbListColumns command returned a linked list pointed to by pColumns

A FOR/EACH loop works pretty much works like a FOR/NEXT loop but  there is no NEXT.

Hope that answers your questions. If not, let me know and I'll try again.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Brian and Larry,

Thanks for the ++ explanation, thought it was just incrementing by 1 but thanks for the confirmation.

Larry, thanks for the explanation of the FOR/EACH - got that with the exception that you say
"but there is no NEXT"

The code example posted here clearly has the NEXT command included.

Do you mean the NEXT in this code is just to denote the end of the FOR/EACH code block?

Thanks,
Andy.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

what I meant is
we're use to
FOR x =....
NEXT x
and with the
FOR EACH...
it's just plain
NEXT
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.