Miranda while for loops

I am looking for a way to do while-loops or for-loops in Miranda.

I'm trying to do something like

while(blablanotfinished) { if(a=true)blabla else blabla } 
+4
source share
3 answers

Miranda does not have while- or for-loops (which in any case does not make sense without a volatile state). In most cases, you can use higher order functions. In cases where there is no higher order function that does what you need, you can use recursion.

For example, if you have the following while-loop in an imperative language:

 f(start) { x = start while( !finished(x) ) { x = next(x) } return x } 

You could express it recursively in Miranda as follows:

 fx = if finished x then x else f (next x) 
+3
source

In Miranda (and generally, in purely functional programming languages) the use of loops, such as WHILE, FOR, etc., is not recommended. It is expected that you iterate through recursion.

+2
source

Like many other functional languages, Miranda has no for- or while loops. Instead, you write loops using recursion, a list of concepts, or higher-order functions .

+2
source

All Articles