How to resolve the algorithm Loops/Foreach step by step in the M2000 Interpreter programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Loops/Foreach step by step in the M2000 Interpreter programming language
Table of Contents
Problem Statement
Loop through and print each element in a collection in order. Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Loops/Foreach step by step in the M2000 Interpreter programming language
Source code in the m2000 programming language
Module Checkit {
\\ Inventories may have keys or keys/values
\\ here keys are values too
Inventory Alfa="Apple", "Banana", "Coconut"
\\ key 30 has value 25, other keys have value same as key.
Inventory Beta=100, 30:=25, 20, 5
Print "Parallel"
k=Each(Alfa)
k1=Each(Alfa End to Start)
k2=Each(Beta)
\\ Parallel iterators
\\ when one of them end then while end too.
\\ so 5 not printed. Print 100, 25, 20
While k,k2, k1 {
Print Eval$(k), Eval$(k1), Eval(k2)
}
Print "Nested"
\\ Nested iterators
k=Each(Alfa)
While k {
k1=Each(Alfa End to Start)
While k1 {
Print Eval$(k), Eval$(k1)
}
}
}
Checkit
You may also check:How to resolve the algorithm Topological sort step by step in the Raku programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm 4-rings or 4-squares puzzle step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Numerical integration step by step in the F# programming language
You may also check:How to resolve the algorithm Abundant, deficient and perfect number classifications step by step in the MAD programming language