What is the is_in_list() method in Euphoria?
Overview
The is_in_list() method in Euphoria lets you determine the availability of an object in a list. Hence, this method can be used in loops and other conditionals statements.
The
is_in_list()is an inbuilt function in Euphoria and is part of thesearch.estandard library. In order to use this method, we have to addinclude std/search.eat the top of our code.
Syntax
is_in_list(search_item, items_list)
Parameters
search_item: This is the object that we are checking to see if it is present in theitems_list.items_list: This is the list that may have thesearch_itemin it.
Return value
The is_in_list() method returns 1 if search_item is in the items_list. Otherwise, it returns 0.
Code
The code below demonstrates how we can use the is_in_list() function.
include std/search.esequence user_age, name, carsname = "spring"user_age = {3,4}cars = "offroads"if is_in_list(user_age, {100, 45, 2, 75, 121}) thenprint(1,user_age)elseputs(1,"not in the list")end ifprintf(1,"\n%d",is_in_list(name,"SPRINGBOARD"))printf(1,"\n%d",is_in_list(cars,{"saloons","trucks","offroads"}))
Explanation
In the code sample above, we use the is_in_list method as a condition of the if statement.
-
Line 2: We include the
search.efile into our program code. -
Line 4: We declare some variables as sequence data type.
-
Lines 5 and 7: We assign values to the variables.
-
Line 9: We provide an
ifstatement, withis_in_list()as one of its conditions to check ifuser_ageis in the provided age list. -
Line 10: We print some of the values returned from the condition on line 9.
-
Lines 11-13: We provide the
elseblock of theifstatement and print some of the values returned. -
Line 15-16: We print the value returned from the
is_in_list()function as an output.