Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What languages do not have looping constructs?

Tags:

recursion

Which languages are recursive-only languages?

like image 966
Brandon Tiqui Avatar asked Feb 28 '10 12:02

Brandon Tiqui


People also ask

Do all languages have for loops?

foreach. Many languages provide a special for loop. This special for loop is sometimes called "foreach" as you iterate over each element in a collection (e.g. an array).

Do functional languages have for loops?

Learning a functional language is a mind-bending experience if you're used to imperative code. Functional languages have no loops, because changing values is verboten—instead of assigning a new value to a local variable you have to make a recursive call and pass the new value as an argument.

Do all programming languages have recursion?

Most computer programming languages support recursion by allowing a function to call itself from within its own code. Some functional programming languages (for instance, Clojure) do not define any looping constructs but rely solely on recursion to repeatedly call code.

Can you program without loops?

Another way we can avoid using imperative loops is through recursion. Recursion is simple. Have a function call itself (which creates a loop) and design an exit condition out of that loop.


3 Answers

It depends on what you mean by looping construct - there are several types. Infinite loops, iterators - loops that count each item in an array or hash - and general loops like C style

for ( int i = 0; i < 10; i++ )

Wikipedia has a table of support for such constructs by language: Loop system cross reference table

To answer your question fully, Haskell and Scheme are two examples of languages that do not have standard for loops built in; they are generally done using recursion.

like image 68
rjh Avatar answered Oct 19 '22 04:10

rjh


Functional programming languages (e.g. Haskell, Erlang) generally don't have loops, nor do function-level languages (e.g. FP, J) or logic languages (e.g. Prolog, Planner). Indeed pretty much the entire group of declarative languages (of which functional, function-level, logic, etc. are a subset) tend not to have looping constructs.

But...

That being said a lot of those have ways of doing much the same as explicit looping. Common Lisp, for example, has macros that give you the ability to do what looks like regular for, while, etc. loops by macro trickery behind the scenes. Dylan (a very un-Lisplike Lisp) goes a step farther and elevates such macros into something that is effectively part of the language (although the semantics can still be defined in terms of recursion and macros). Too, common operations in functional languages like zips, maps, folds, takes, etc. are higher-level functions that mask explicit recursion behind a function call and act in many ways like assorted loop constructs.

like image 36
JUST MY correct OPINION Avatar answered Oct 19 '22 05:10

JUST MY correct OPINION


Erlang does not have looping constructs. You use recursion instead.

like image 4
brabster Avatar answered Oct 19 '22 05:10

brabster