IonicWind Software

IWBasic => General Questions => Topic started by: Andy on December 03, 2015, 12:59:56 AM

Title: EACH command and ++
Post by: Andy on December 03, 2015, 12:59:56 AM
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.
:)

Title: Re: EACH command and ++
Post by: Brian on December 03, 2015, 05:03:35 AM
Andy,

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

Brian
Title: Re: EACH command and ++
Post by: LarryMc on December 03, 2015, 07:33:43 AM
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.
Title: Re: EACH command and ++
Post by: Andy on December 03, 2015, 11:13:22 PM
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.

Title: Re: EACH command and ++
Post by: LarryMc on December 04, 2015, 12:27:01 AM
what I meant is
we're use to
FOR x =....
NEXT x
and with the
FOR EACH...
it's just plain
NEXT
Title: Re: EACH command and ++
Post by: Andy on December 04, 2015, 02:17:45 AM
Thanks Larry - got it!

Andy.
:)