Idiom #6 Iterate over list values
Do something with each item x of the list (or array) items, regardless indexes.
- Ada
- C
- C
- Caml
- Clojure
- Cobol
- C++
- C#
- D
- D
- Dart
- Elixir
- Elixir
- Erlang
- Erlang
- Fortran
- Go
- Groovy
- Groovy
- Groovy
- Haskell
- JS
- JS
- JS
- JS
- JS
- Java
- Java
- Java
- Java
- Java
- Java
- Kotlin
- Kotlin
- Kotlin
- Lisp
- Lua
- Obj-C
- PHP
- PHP
- Pascal
- Perl
- Perl
- Python
- Python
- Python
- Ruby
- Ruby
- Rust
- Rust
- Scala
- Scala
- Scala
- Scheme
- Scheme
- Scheme
- Smalltalk
- Smalltalk
- VB
Idiom #7 Iterate over list indexes and values
Print each index i with its value x from an array-like collection items
Idiom #286 Iterate over characters of a string
Print a line "Char i is c" for each character c of the string s, where i is the character index of c in s (not the byte index).
Make sure that multi-byte characters are properly handled, and count for a single character.
Idiom #143 Iterate alternatively over two lists
Iterate alternatively over the elements of the lists items1 and items2. For each iteration, print the element.
Explain what happens if items1 and items2 have different size.
Idiom #13 Iterate over map keys and values
Access each key k with its value x from an associative array mymap, and print them.
Idiom #113 Iterate over map entries, ordered by values
Print each key k with its value x from an associative array mymap, in ascending order of x.
Multiple entries may exist for the same value x.
Idiom #43 Break outer loop
Look for a negative value v in 2D integer matrix m. Print it and stop searching.
Idiom #71 Echo program implementation
Basic implementation of the Echo program: Print all arguments except the program name, separated by space, followed by newline.
Skip the first argument if necessary, concatenate arguments as strings, append newline and print it to stdout.
Idiom #136 Remove all occurrences of a value from a list
Remove all occurrences of the value x from list items.
This will alter the original list or return a new list, depending on which is more idiomatic.
Idiom #2 Print Hello 10 times
Loop to execute some code a constant number of times
- Ada
- C
- Caml
- Clojure
- Cobol
- C++
- C++
- C++
- C#
- C#
- C#
- D
- D
- Dart
- Dart
- Elixir
- Erlang
- Fortran
- Go
- Go
- Go
- Groovy
- Haskell
- JS
- JS
- JS
- JS
- Java
- Java
- Java
- Java
- Java
- Java
- Java
- Kotlin
- Kotlin
- Kotlin
- Lisp
- Lua
- Lua
- Lua
- Lua
- Obj-C
- PHP
- PHP
- Pascal
- Perl
- Perl
- Perl
- Prolog
- Python
- Python
- Python
- Python
- Python
- Python
- Ruby
- Ruby
- Ruby
- Rust
- Rust
- Scala
- Scala
- Scheme
- Scheme
- Scheme
- Smalltalk
- Smalltalk
- VB