-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e2f5dd
commit de38a57
Showing
3 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
## 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
## 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. |