Skip to content

Commit

Permalink
add range documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
AvicennaJr committed Oct 5, 2024
1 parent 27478d1 commit abf6b57
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
60 changes: 60 additions & 0 deletions docs/src/en/mfululizo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: Range Function (mfululizo)
titleTemplate: Range funtion to generate a sequence of numbers.
---

## Range Function (mfululizo)

The `mfululizo` function generates a sequence of numbers. It can be used in loops or to create arrays of sequential numbers.

### Syntax

```go
mfululizo(end)
mfululizo(start, end)
mfululizo(start, end, step)
```

### Parameters

- `end`: The upper limit of the sequence (exclusive).
- `start` (optional): The starting value of the sequence. Default is 0.
- `step` (optional): The increment between each number in the sequence. Default is 1.

### Return Value

Returns an array of integers.

### Examples

```go
// Generate numbers from 0 to 4
kwa i katika mfululizo(5) {
andika(i)
}
// Output: 0 1 2 3 4

// Generate numbers from 1 to 9
kwa i katika mfululizo(1, 10) {
andika(i)
}
// Output: 1 2 3 4 5 6 7 8 9

// Generate even numbers from 0 to 8
kwa i katika mfululizo(0, 10, 2) {
andika(i)
}
// Output: 0 2 4 6 8

// Generate numbers in reverse order
kwa i katika mfululizo(10, 0, -1) {
andika(i)
}
// Output: 10 9 8 7 6 5 4 3 2 1
```

### Notes

- The `end` value is exclusive, meaning the sequence will stop before reaching this value.
- If a negative `step` is provided, `start` should be greater than `end`.
- The `step` value cannot be zero.
60 changes: 60 additions & 0 deletions docs/src/mfululizo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: Mfululizo
titleTemplate: Kitendakazi cha mfululizo kuzalisha mlolongo wa nambari.
---

## Kitendakazi cha Mfululizo

Kitendakazi cha `mfululizo` hutoa mfululizo wa nambari, sawa na kitendakazi cha `range()` cha Python. Kinaweza kutumika katika vitanzi au kuunda safu za nambari zinazofuatana.

### Muundo

```go
mfululizo(mwisho)
mfululizo(mwanzo, mwisho)
mfululizo(mwanzo, mwisho, hatua)
```

### Vipengele

- `mwisho`: Kikomo cha juu cha mfululizo (haijumuishwi).
- `mwanzo` (si lazima): Thamani ya kuanzia ya mfululizo. Chaguo-msingi ni 0.
- `hatua` (si lazima): Ongezeko kati ya kila nambari katika mfululizo. Chaguo-msingi ni 1.

### Thamani Inayorudishwa

Hurudisha safu ya nambari kamili.

### Mifano

```go
// Toa nambari kutoka 0 hadi 4
kwa i katika mfululizo(5) {
andika(i)
}
// Tokeo: 0 1 2 3 4

// Toa nambari kutoka 1 hadi 9
kwa i katika mfululizo(1, 10) {
andika(i)
}
// Tokeo: 1 2 3 4 5 6 7 8 9

// Toa nambari shufwa kutoka 0 hadi 8
kwa i katika mfululizo(0, 10, 2) {
andika(i)
}
// Tokeo: 0 2 4 6 8

// Toa nambari kwa mpangilio wa kurudi nyuma
kwa i katika mfululizo(10, 0, -1) {
andika(i)
}
// Tokeo: 10 9 8 7 6 5 4 3 2 1
```

### Vidokezo

- Thamani ya `mwisho` haijumuishwi, ikimaanisha mfululizo utasimama kabla ya kufikia thamani hii.
- Ikiwa `hatua` hasi imetolewa, `mwanzo` inapaswa kuwa kubwa kuliko `mwisho`.
- Thamani ya `hatua` haiwezi kuwa sifuri.

0 comments on commit abf6b57

Please sign in to comment.