mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
30
doc/tut1.rst
30
doc/tut1.rst
@@ -380,6 +380,28 @@ Since counting up occurs so often in programs, Nim also has a `..
|
||||
for i in 1..10:
|
||||
...
|
||||
|
||||
Zero-indexed counting have two shortcuts ``..<`` and ``..^`` to simplify counting to one less then the higher index:
|
||||
|
||||
.. code-block:: nim
|
||||
for i in 0..<10:
|
||||
... # 0..9
|
||||
|
||||
or
|
||||
|
||||
.. code-block:: nim
|
||||
var s = "some string"
|
||||
for i in 0..<s.len:
|
||||
...
|
||||
|
||||
Other useful iterators for collections (like arrays and sequences) are
|
||||
* ``items`` and ``mitems``, which provides immutable and mutable elements respectively, and
|
||||
* ``pairs`` and ``mpairs`` which provides the element and an index number (immutable and mutable respectively)
|
||||
|
||||
.. code-block:: nim
|
||||
for indx, itm in ["a","b"].pairs:
|
||||
echo itm, " at index ", indx
|
||||
# => a at index 0
|
||||
# => b at index 1
|
||||
|
||||
Scopes and the block statement
|
||||
------------------------------
|
||||
@@ -1516,8 +1538,14 @@ Example:
|
||||
A subtle issue with procedural types is that the calling convention of the
|
||||
procedure influences the type compatibility: procedural types are only compatible
|
||||
if they have the same calling convention. The different calling conventions are
|
||||
listed in the `manual <manual.html>`_.
|
||||
listed in the `manual <manual.html#types-procedural-type>`_.
|
||||
|
||||
Distinct type
|
||||
-------------
|
||||
A Distinct type allows for the creation of new type that "does not imply a subtype relationship between it and its base type".
|
||||
You must EXPLICITLY define all behaviour for the distinct type.
|
||||
To help with this, both the distinct type and its base type can cast from one type to the other.
|
||||
Examples are provided in the `manual <manual.html#types-distinct-type>`_.
|
||||
|
||||
Modules
|
||||
=======
|
||||
|
||||
Reference in New Issue
Block a user