Here is a program for a linear search I wrote in YASS some few months ago.
YASS
function linearSearch($item_list, $search_item) : number | boolean { $found = false $index = 0 $position = -1 while ($index < count($item_list) and $found == false){ if ($item_list[$index] == $search_item){ $found = true $position = $index } $index++ } if($found){ print("Item found at position", $position) } else{ print("Item not found") } } function main(){ $l = [3, 5, 7] linearSearch($l, 6) }
And here it is converted to Python using ZenPy:
Python
def linearSearch(item_list, search_item): found = False index = 0 position = -1 while index < len(item_list) and found == False: if item_list[index] == search_item: found = True position = index index += 1 if found: print("Item found at position", position) else: print("Item not found") def main(): l = [3, 5, 7] linearSearch(l, 5) main()
Posted in ZPE Programming Environment

There are no comments on this page.
Comments are welcome and encouraged, including disagreement and critique. However, this is not a space for abuse. Disagreement is welcome; personal attacks, harassment, or hate will be removed instantly. This site reflects personal opinions, not universal truths. If you can’t distinguish between the two, this probably isn’t the place for you. The system temporarily stores IP addresses and browser user agents for the purposes of spam prevention, moderation, and safeguarding. This data is automatically removed after fourteen days.
Comments powered by BalfComment