Category talk:EasyLang

From Rosetta Code
Revision as of 05:45, 21 December 2022 by Jazzedpineda (talk | contribs) (Associative arrays)

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$ = ""
.