Category talk:EasyLang: Difference between revisions

From Rosetta Code
Content added Content deleted
(Added snippets section)
 
(Associative arrays)
Line 24: Line 24:
.
.
index = 0
index = 0
.
</syntaxhighlight>

==Associative arrays==
The syntax for an associative arrays in EasyLang should look like this:
<syntaxhighlight lang="easylang">associative$[][] = [ [ 1 "associative" ] [ 2 "arrays" ] ]</syntaxhighlight>
===Indexing associative arrays===
For associative number arrays:
<syntaxhighlight lang="easylang">
func indexAssoc index . array[][] item .
for i = 1 to len array[][]
if array[i][1] = index
item = array[i][2]
break 2
.
.
item = number "nan"
.
</syntaxhighlight>
Foor associative string arrays:
<syntaxhighlight lang="easylang">
func indexStrAssoc index$ . array$[][] item$ .
for i = 1 to len array$[][]
if array$[i][1] = index$
item$ = array$[i][2]
break 2
.
.
item$ = ""
.
.
</syntaxhighlight>
</syntaxhighlight>

Revision as of 05:45, 21 December 2022

Here are some common code snippets for implementing tasks in EasyLang.

Find in array

This function is for number arrays:

func findInArray array[] item . index .
   for i = 1 to len array[]
      if array[i] = item
         index = i
         break 2
      .
   .
   index = 0
.

This function is for string arrays:

func findInStrArray array$[] item$ . index .
   for i = 1 to len array$[]
      if array$[i] = item$
         index = i
         break 2
      .
   .
   index = 0
.

Associative arrays

The syntax for an associative arrays in EasyLang should look like this:

associative$[][] = [ [ 1 "associative" ] [ 2 "arrays" ] ]

Indexing associative arrays

For associative number arrays:

func indexAssoc index . array[][] item .
   for i = 1 to len array[][]
      if array[i][1] = index
         item = array[i][2]
         break 2
      .
   .
   item = number "nan"
.

Foor associative string arrays:

func indexStrAssoc index$ . array$[][] item$ .
   for i = 1 to len array$[][]
      if array$[i][1] = index$
         item$ = array$[i][2]
         break 2
      .
   .
   item$ = ""
.