Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2025/26/2
* archívum


Linkek

* kalendárium
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C#
* D lang.
* Java
* Nim
* Nim2
  + exercises
* XC=BASIC
* old
  ◇C++, ◇Clojure, ◇Scala


[ edit | logout ]
[ sandbox | passwd ]

mitems(), mpairs()

These are mutable iterators. (The "m" prefix stands for "mutable").

items(), pairs(): read-only iterators (see here)

mitems()

Iterate over the elements. Use this if you want to modify the elements.

var li = @[1, 2, 3]    # must be `var` (not `let`)

for x in mitems(li):
  x *= 10

echo li     # @[10, 20, 30]

Think of the loop variable x that it's a reference (alias?) on the current element. When you modify the value of x, you actually modify the value of the current element.

Make sure that you iterate over something mutable. Otherwise you cannot change its elements.

mpairs()

Similar to mitems(), but you also get the index of the current element. Use this if you want to modify the elements.

var li = @["aa", "bb", "cc"]    # must be `var` (not `let`)

for idx, x in mpairs(li):
  x.add("!!!")

echo li     # @["aa!!!", "bb!!!", "cc!!!"]
Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2026 May 06, 20:27