Swahili code examples

Learn Swahili programming by reading real code.

These SwahiliPro examples show how familiar programming ideas look when the readable commands are written in Swahili. Copy them into a .swa file and run them with the swa CLI.

Hello world

Print a simple message using andika.

andika("Habari Dunia!")

Variables

Store and combine values using acha.

acha jina = "Amina"
acha umri = 24
andika(jina + " ana miaka " + umri)

Conditions

Make decisions with ikiwa and vinginevyo.

acha umri = 20

ikiwa (umri >= 18) {
  andika("Karibu")
} vinginevyo {
  andika("Bado mdogo")
}

Loops

Iterate through an end-exclusive range.

kwa i katika 1..5 {
  andika(i)
}

Functions

Create reusable logic and return a result.

jumlisha(a, b) {
  rudisha a + b
}

andika(jumlisha(4, 6))

Lists

Create a list, index it and append another value.

acha miji = ["Nairobi", "Mombasa"]
ongeza(miji, "Kisumu")
andika(miji[0])