Chapterبەش 5 · Lectureوانە 5.1
Programming Languages and Algorithmsزمانەکانی بەرنامەسازی و ئەلگۆریزمەکان
Plan a program with an algorithm, a flowchart and pseudocode, compare high- and low-level languages, explain compilers and interpreters, read the English keywords in code, and describe a process with sequence words and if-sentences.
بە ، و پلانی دابنێ، و بەراورد بکە، و ڕوون بکەرەوە، وشە ئینگلیزییەکانی ناو کۆد بخوێنەوە و پرۆسەیەک بە وشەی ڕیزبەندی و وەسف بکە.
What you will learnچی فێر دەبیت
- Explain what an algorithm, pseudocode and a flowchart are, and name the flowchart symbols.
- Compare high-level and low-level languages, and compilers and interpreters.
- Use the word families program, compile and debug correctly.
- Describe a process with sequence words (first, then, next, finally) and if-sentences.
- Read the English keywords in code aloud: if, else, while, for, return, true and false.
- ڕوونی بکەرەوە ، و چین و هێماکانی بە ئینگلیزی ناو ببە.
- و ، هەروەها و بەراورد بکە.
- خێزانە وشەکانی program، compile و debug بە دروستی بەکاربهێنە.
- پرۆسەیەک بە وشەی ڕیزبەندی (first, then, next, finally) و وەسف بکە.
- ناو کۆد بە ئینگلیزی و بە دەنگی بەرز بخوێنەوە: if، else، while، for، return، true و false.
EN shows the lessons for English-speaking students; کوردی shows the lessons for Kurdish-speaking students. کوردی وانەکانی خوێندکارانی کوردزمان پیشان دەدات؛ EN وانەکانی خوێندکارانی ئینگلیزیزمان پیشان دەدات.
Warm-up: an algorithm for teaدەستپێک: ئەلگۆریزمێک بۆ چا
You follow algorithms every day. Here is one that every Kurdish tea house knows: how to make tea.
هەموو ڕۆژێک جێبەجێ دەکەیت. ئەمە یەکێکیانە کە هەموو چایخانەیەکی کوردی دەیزانێت: چۆن چا دروست بکەیت.
Fill the kettle with water and boil it.
کەتڵییەکە پڕ بکە لە ئاو و بیکوڵێنە.
Put two spoons of black tea in the small teapot.
دوو کەوچک چای ڕەش بخە ناو قۆرییە بچووکەکەوە.
Pour hot water into the teapot, and put it on top of the kettle.
ئاوی گەرم بکە بە قۆرییەکەدا و بیخە سەر کەتڵییەکە.
Wait about ten minutes.
نزیکەی دە خولەک چاوەڕێ بکە.
Pour tea into a small glass. If the guest wants sugar, add sugar.
چا بکە بە ئیستیکانێکی بچووکدا. ئەگەر میوانەکە شەکری دەوێت، شەکری تێ بکە.
Repeat step 5 until every guest has a glass.
هەنگاوی ٥ دووبارە بکەرەوە تا هەموو میوانێک ئیستیکانێکی هەبێت.
This list has the three building blocks of every program: sequence (steps in order), selection (if the guest wants sugar…) and repetition (repeat until every guest has a glass). An algorithm is exactly this: a clear list of steps that solves a problem.
ئەم لیستە هەر سێ بەردی بناغەی هەموو لەخۆ دەگرێت: ڕیزبەندی (sequence: هەنگاوەکان بە ڕیز)، هەڵبژاردن (selection: if میوانەکە شەکری دەوێت…) و دووبارەکردنەوە (repetition: repeat until هەموو میوانێک ئیستیکانێکی هەبێت). ڕێک ئەمەیە: لیستێکی ڕوونی هەنگاوەکان کە کێشەیەک چارەسەر دەکات.
Key words 1: planning a programوشە سەرەکییەکان ١: پلاندانانی بەرنامەیەک
- algorithmnoun/ˈælɡərɪðəm/A finite list of clear steps that solves a problem or does a task. Programmers often plan an algorithm with or a before they write the code.An algorithm must be clear: each step can mean only one thing.دەبێت ڕوون بێت: هەر هەنگاوێک دەبێت تەنها یەک واتای هەبێت.
- pseudocodenoun (uncountable)/ˈsjuːdəʊkəʊd/— pseudo واتە «ساختە، نیمچە». پیتی pـی سەرەتا ناخوێندرێتەوە.A plan of a program written in short, simple lines that look like English, not in a real . It shows the steps of an , but a computer cannot run it.Write the pseudocode first, and then the real code.سەرەتا بنووسە، پاشان کۆدە ڕاستەقینەکە.
- flowchartnoun/ˈfləʊtʃɑːt/A diagram that shows the steps of an with shapes and arrows: ovals for start and end, rectangles for actions, and diamonds for yes/no questions.The flowchart shows every decision as a diamond.هەموو بڕیارێک وەک چوارگۆشەیەکی لار پیشان دەدات.
- programnoun / verb/ˈprəʊɡræm/— لە IT هەمیشە program دەنووسرێت. programme (بەریتانی) بۆ تەلەڤزیۆن و خوێندنە.A set of instructions that a computer follows to do a job. A program can be one small or many files working together.This program calculates the average of the marks.ئەم تێکڕای نمرەکان دەژمێرێت.
- programming languagenoun/ˈprəʊɡræmɪŋ ˌlæŋɡwɪdʒ/A language with strict rules that people use to give instructions to a computer. PHP, JavaScript and Python are programming languages.Python and PHP are popular programming languages.Python و PHP دوو بەناوبانگن.
- source codenoun (uncountable)/ˈsɔːs kəʊd/— code لێرەدا : a lot of code، نەک many codes.The text of a program as people write it in a programming language, for example the code in a
.py,.phpor.javafile. The computer cannot run it directly: a or an translates it.Programmers write source code in a text editor or an IDE.لە یان دەنووسن. - software developer (programmer)noun/ˈsɒftweə dɪˌveləpə(r)/A person who designs, writes, tests and fixes . Many developers work in one area, for example web, mobile apps or games.My sister is a software developer at a bank in Erbil.خوشکەکەم لە بانکێک لە هەولێر.
- bugnoun/bʌɡ/A mistake in a program that makes it behave wrongly. Some bugs cause error messages; others quietly give wrong results.There's a bug on the login page: it accepts an empty password.لە لاپەڕەی هەیە: بەتاڵ قبووڵ دەکات.
- debuggingnoun/ˌdiːˈbʌɡɪŋ/— کارەکەی to debugـە: دۆزینەوە و لابردن.Finding and fixing in a program. Common methods: read the error message, print values (
print()in Python,echoorvar_dump()in PHP), trace the code by hand and test small parts.Debugging took longer than writing the program.لە نووسینی زیاتر کاتی برد.
The full story of this bug, and what programming is, are in the Fundamentals of Programming lesson Why mistakes are called bugs.
چیرۆکی تەواوی ئەم و ئەوەی چییە، لە وانەی بۆچی هەڵەکان پێیان دەوترێت باگ؟ لە بنەماکانی .
Reading: from an idea to an appخوێندنەوە: لە بیرۆکەوە بۆ ئەپ
Aram is a second-year computer science student in Erbil. His uncle has a small supermarket, and every evening he adds up the day's sales by hand. Aram decided to write a program to do it for him.
First, he made sure that he understood the problem. What information goes in? What should come out? He talked to his uncle and wrote everything down.
Next, he planned the solution. He wrote an in and drew a . This helped him to see every decision before he wrote any real code.
Then he wrote the in Python, a . High-level languages use English words like if, while and print, so people can read them easily. A computer, however, only understands : long lists of 0s and 1s. Python is usually run by an , which translates the program and runs it step by step. Other languages, like C, use a , which translates the whole program into machine code before it runs.
After that, Aram tested the program with real numbers from the shop. He found two bugs. The first was a syntax error, a missing bracket, and Python showed an error message at once. The second was a : the program ran, but the total was wrong because it forgot the last sale of the day. it took an hour.
Finally, he wrote short instructions for his uncle. Now the day's sales are added up in two seconds.
Kurdish translationوەرگێڕانی کوردی
ئارام خوێندکاری قۆناغی دووەمی زانستی لە هەولێر. مامی سوپەرمارکێتێکی بچووکی هەیە و هەموو ئێوارەیەک بە دەست فرۆشی ڕۆژەکە کۆ دەکاتەوە. ئارام بڕیاری دا بنووسێت کە ئەم کارەی بۆ بکات.
سەرەتا دڵنیا بووەوە کە لە کێشەکە تێگەیشتووە. چ زانیارییەک دەچێتە ژوورەوە؟ دەبێت چی بێتە دەرەوە؟ قسەی لەگەڵ مامی کرد و هەموو شتێکی نووسییەوە.
دواتر پلانی چارەسەرەکەی دانا. بە نووسی و کێشا. ئەمە یارمەتی دا پێش ئەوەی هیچ کۆدێکی ڕاستەقینە بنووسێت، هەموو بڕیارێک ببینێت.
پاشان بە Python نووسی، کە . وشەی ئینگلیزیی وەک if، while و print بەکاردەهێنن، بۆیە خەڵک بە ئاسانی دەیانخوێننەوە. بەڵام تەنها تێدەگات: لیستی درێژی ٠ و ١. Python زۆرجار بە کار دەکات کە وەردەگێڕێت و هەنگاو بە هەنگاو جێبەجێی دەکات. زمانەکانی تر، وەک C، بەکاردەهێنن کە هەموو پێش کارکردن وەردەگێڕێتە سەر .
دوای ئەوە، ئارام بە ژمارەی ڕاستەقینەی دووکانەکە تاقی کردەوە. دوو دۆزییەوە. یەکەمیان بوو، کەوانەیەک کەم بوو و Python دەستبەجێ پیشان دا. دووەمیان بوو: کاری کرد، بەڵام کۆی گشتی هەڵە بوو، چونکە دوایین فرۆشی ڕۆژەکەی لە بیر دەچوو. کاتژمێرێکی خایاند.
لە کۆتاییدا ڕێنمایی کورتی بۆ مامی نووسی. ئێستا فرۆشی ڕۆژەکە لە دوو چرکەدا کۆ دەکرێتەوە.
Put Aram's steps in order.هەنگاوەکانی ئارام ڕیز بکە.
Understand the problem → plan the solution (algorithm, pseudocode, flowchart) → write the source code → translate and run it → test and debug → write instructions (documentation).
تێگەیشتن لە کێشەکە ← پلانی چارەسەر (، ، ) ← نووسینی ← وەرگێڕان و کارپێکردن ← و ← نووسینی ڕێنمایی ().
Key words 2: languages and translatorsوشە سەرەکییەکان ٢: زمانەکان و وەرگێڕەکان
- high-level languagenoun/ˌhaɪ ˌlevl ˈlæŋɡwɪdʒ/A that uses words and symbols close to human language, so people can read and write it easily. A or an translates it for the computer. PHP, Python and Java are high-level languages.Python, Java and PHP are high-level languages.Python، Java و PHP .
- low-level languagenoun/ˌləʊ ˌlevl ˈlæŋɡwɪdʒ/A that is close to the computer's own instructions, such as or . It is fast and gives full control, but it is hard for people to read.Low-level languages are close to the hardware and hard for people to read.نزیکن لە و خوێندنەوەیان بۆ مرۆڤ قورسە.
- machine codenoun (uncountable)/məˈʃiːn kəʊd/Instructions written only in numbers (0s and 1s) that the can run directly. It is the only language the processor understands, so programs in other languages must be translated first.The CPU can only run machine code: instructions made of 0s and 1s.تەنها دەتوانێت جێبەجێ بکات: فەرمانی پێکهاتوو لە ٠ و ١.
- assembly languagenoun/əˈsembli ˌlæŋɡwɪdʒ/A that uses short words such as
MOVandADDfor each instruction. A program called an assembler turns it into machine code.In assembly language, short words like MOV and ADD stand for machine instructions.لە ، وشەی کورتی وەک MOV و ADD لە جیاتی فەرمانەکانی ئامێر دادەنرێن. - assemblernoun/əˈsemblə(r)/A that translates into . It does for assembly language what a does for a .An assembler turns assembly language into machine code.دەکات بە .
- compilernoun/kəmˈpaɪlə(r)/A program that translates a whole program's source code before it runs: into machine code (C, C++) or into for a virtual machine (Java's
javac). Python and PHP do this step automatically when they run a file.The compiler found three errors before the program could run.پێش ئەوەی کار بکات سێ هەڵەی دۆزییەوە. - interpreternoun/ɪnˈtɜːprɪtə(r)/A program that reads source code and runs it statement by statement, without first making a separate machine-code file. Python and PHP are run by interpreters (which first turn the code into behind the scenes).The interpreter stops at the first line with an error.لە یەکەم دێڕی هەڵەدار دەوەستێت.
- syntax errornoun/ˈsɪntæks ˌerə(r)/An error found before a program runs, because the code breaks the rules — for example a missing
:in Python or a missing;in PHP. Nothing in that file runs; Python reportsSyntaxError, PHPParse error.A missing semicolon is a common syntax error in PHP.نەبوونی باوە لە PHP. - logic errornoun/ˈlɒdʒɪk ˌerə(r)/A mistake in the logic of a . The program runs with no , but the result is wrong, for example because it uses
>where it should use>=.A logic error does not stop the program. It just gives the wrong answer.ناوەستێنێت. تەنها وەڵامی هەڵە دەدات.
| Pointخاڵ | Compiler | Interpreter |
|---|---|---|
| How it translatesچۆن وەردەگێڕێت | the whole program at once, before it runsهەموو بە یەکجار، پێش کارکردن | one statement at a time, while the program runsیەک لە هەر جارێکدا، لە کاتی کارکردندا |
| What it makesچی دروست دەکات | a separate machine-code file (for example an .exe file) جیای (بۆ نموونە .exe) | no separate file: it is needed every time the program runsهیچ جیا نییە: هەموو جارێک کە کار دەکات پێویستە |
| Errorsهەڵەکان | listed together after compilingدوای وەرگێڕان پێکەوە لیست دەکرێن | the program stops at the first error لە یەکەم هەڵەدا دەوەستێت |
| Speedخێرایی | the finished program usually runs faster زۆرجار خێراتر کار دەکات | usually slower, but quicker to test and changeزۆرجار خاوترە، بەڵام تاقیکردنەوە و گۆڕینی خێراترە |
| Examplesنموونە | C, C++, Go | PHP, JavaScript, Python (usually)PHP، JavaScript، Python (زۆرجار) |
The levels of languages are taught in Low-level and high-level languages, and how a translated program becomes machine instructions in From your code to machine instructions.
ئاستەکانی زمان لە زمانە ئاستنزمەکان و زمانە ئاستبەرزەکان فێر دەکرێن و وەرگێڕدراو چۆن دەبێتە ئامێر لە لە کۆدەکەتەوە بۆ ڕێکارنامەکانی ئامێر.
A calm short cartoon: how an interpreter translates one line at a time, how a compiler translates the whole program, and the key terms.
کارتۆنێکی کورت و ئارام: چۆن دێڕ بە دێڕ وەردەگێڕێت، چۆن هەموو پێکەوە وەردەگێڕێت و زاراوە سەرەکییەکان.
Whole video: how interpreters and compilers translate a program.
هەموو ڤیدیۆکە: و چۆن وەردەگێڕن.
Word focus: program, compile, debugوشە: program، compile، debug
One root gives many words. -er/-or often means a person or a tool (programmer, compiler), -ing and -ion name an activity (programming, compilation), and -able means “can be done” (executable = can be run).
یەک ڕەگ چەندین وشە دروست دەکات. -er / -or زۆرجار کەس یان ئامراز دەگەیەنێت (programmer، compiler)، -ing و -ion ناوی چالاکییەکن (programming، compilation) و -able واتە «دەکرێت بکرێت» (executable = دەکرێت کار پێ بکرێت). ئەمانە .
| Verbکار | Activity or thingچالاکی یان شت | Person or toolکەس یان ئامراز | Adjectiveئاوەڵناو |
|---|---|---|---|
| program | programming, a program | programmer | programmable |
| compile | compilation | compiler | compiled |
| debug | debugging, a bug | debugger | buggy |
| execute | execution | — | executable |
| specify | specification | — | specific |
Language focus: describing a processزمان: وەسفکردنی پرۆسەیەک
| Jobئەرک | Wordsوشەکان | Exampleنموونە |
|---|---|---|
| Order of stepsڕیزبەندیی هەنگاوەکان | First, … Then … Next, … After that, … Finally, … | First, the program sets the counter to 0. Then it asks for the PIN. |
| A decisionبڕیار | If …, … / If not, … / Otherwise, … | If the PIN is correct, the program shows “Welcome”. If not, it adds 1 to the counter. |
| Repetitionدووبارەکردنەوە | repeat … until … / while … | It repeats these steps until the PIN is correct. |
| Purposeمەبەست | to + verb | The program uses a counter to count the attempts. |
To describe a process, use the present simple (the program checks…) or the present passive (the PIN is checked), and join the steps with sequence words. For decisions, use the zero conditional, if + present simple, present simple: If the PIN is wrong, the counter goes up by one. Don't use will: the result happens every time, so it is a fact, not a prediction.
بۆ وەسفکردنی پرۆسەیەک بەکاربهێنە (the program checks…) و هەنگاوەکان بە وشەی ڕیزبەندی ببەستەوە: First = یەکەم/سەرەتا، Then = پاشان، Next = دواتر، After that = دوای ئەوە، Finally = لە کۆتاییدا.
بۆ بڕیار بەکاربهێنە: If the PIN is wrong, the counter goes up by one. لە کوردیدا دوای «ئەگەر» کار بە شێوەی داخوازی دێت: «ئەگەر PINەکە هەڵە بێت». بەڵام لە ئینگلیزیدا دوای if دێت: If the PIN is wrong، نەک If the PIN will be wrong یان If the PIN be wrong.
Language focus: describing a processزمان: وەسفکردنی پرۆسەیەک
If not, otherwise, until, whileIf not، otherwise، until، while
For the other branch, use if not or otherwise. For loops, use until (stop when something becomes true) or while (continue as long as something is true). Note that until and while say the opposite: repeat until the PIN is correct = repeat while the PIN is wrong.
ئینگلیزی هەمیشە بکەری پێویستە. لە کوردیدا دەڵێین «ئەگەر هەڵە بێت، دەوەستێت» و بکەر لە کۆتایی کارەکەدا دیارە. لە ئینگلیزیدا دەبێت it بنووسیت: If it is wrong, it stops.، نەک If is wrong, stops. بۆ دووبارەکردنەوە: until = «تا ئەو کاتەی»، while = «هەتا… بێت».
One algorithm, two ways: flowchart and pseudocodeیەک ئەلگۆریزم، دوو ڕێگا: هێڵکاریی ڕەوت و نیمچەکۆد
Programmers plan with two tools. A flowchart shows the steps as shapes joined by arrows. Pseudocode writes the same steps as short, English-like lines. Neither one is a real programming language, so a computer can't run them, but every programmer can read them. The full lesson, with worked examples, is Algorithms, Pseudocode and Flowcharts in Fundamentals of Programming.
بە دوو ئامراز پلان دادەنێن. هەنگاوەکان وەک شێوەی بەیەکەوە بەستراو بە تیر پیشان دەدات. هەمان هەنگاوەکان وەک دێڕی کورتی وەک ئینگلیزی دەنووسێت. هیچیان ڕاستەقینە نین، بۆیە ناتوانێت جێبەجێیان بکات، بەڵام هەموو دەتوانێت بیانخوێنێتەوە. وانە تەواوەکە، بە نموونەی چارەسەرکراوەوە، ئەلگۆریزمەکان، نیمچەکۆد و هێڵکارییەکانی ڕەوتـە لە بنەماکانی .
Learn what each flowchart shape means and how to turn a flowchart into pseudocode, step by step.
فێردەبیت هەر شێوەیەکی واتای چییە و چۆن بکەیتە ، هەنگاو بە هەنگاو.
Watch 0:26–6:56: flowchart shapes and turning a flowchart into pseudocode.
لە 0:26 تا 6:56 سەیر بکە: شێوەکانی و گۆڕینی بۆ .
One algorithm, two ways: flowchart and pseudocodeیەک ئەلگۆریزم، دوو ڕێگا: هێڵکاریی ڕەوت و نیمچەکۆد
The PIN algorithmئەلگۆریزمی PIN
Follow the purple arrow: when the PIN is wrong and attempts is not yet 3, the algorithm goes back to INPUT pin. That is a loop (REPEAT … UNTIL). Each blue diamond is a decision (IF … THEN). Notice the English: almost every line of pseudocode is an English word in capital letters.
تیرە مۆرەکە بگرە: کاتێک PINەکە هەڵەیە و attempts هێشتا نەگەیشتووەتە ٣، دەگەڕێتەوە بۆ INPUT pin. ئەمە (REPEAT … UNTIL). هەر چوارگۆشەیەکی لاری شین بڕیارێکە (IF … THEN). سەرنجی ئینگلیزییەکە بدە: نزیکەی هەموو دێڕێکی وشەیەکی ئینگلیزییە بە پیتی گەورە.
Describe the PIN algorithm in 5–7 English sentences, for someone who can't read flowcharts. Use First, Then, If…, If not…, until and Finally.
PIN بە ٥–٧ ڕستەی ئینگلیزی وەسف بکە، بۆ کەسێک کە ناتوانێت بخوێنێتەوە. First, Then, If…, If not…, until و Finally بەکاربهێنە.
Show answerوەڵامەکە پیشان بدە
First, the program sets the number of attempts to zero. Then it asks the user to type their PIN. If the PIN is the same as the saved PIN, the program shows “Welcome” and stops. If not, it adds one to the number of attempts. If the number of attempts is three, the program shows “Card blocked” and stops. Otherwise, it asks for the PIN again. The program repeats these steps until the PIN is correct or the user has tried three times.
Kurdish translationوەرگێڕانی کوردی
سەرەتا ژمارەی هەوڵەکان دەکات بە سفر. پاشان داوا لە دەکات PINـەکەی بنووسێت. ئەگەر PINـەکە وەک PINـە پاشەکەوتکراوەکە بێت، «Welcome» پیشان دەدات و دەوەستێت. ئەگەر نا، یەک بۆ ژمارەی هەوڵەکان زیاد دەکات. ئەگەر ژمارەی هەوڵەکان سێ بێت، «Card blocked» پیشان دەدات و دەوەستێت. ئەگەرنا، دووبارە داوای PIN دەکات. ئەم هەنگاوانە دووبارە دەکاتەوە تا PINـەکە دروست دەبێت یان سێ جار هەوڵ دەدات.
Reading the English in codeخوێندنەوەی ئینگلیزیی ناو کۆد
Most programming languages use English keywords. If you know what the English words mean, you can often guess what a piece of code does, even in a language you have never learned.
زۆربەی ئینگلیزی بەکاردەهێنن. ئەگەر واتای وشە ئینگلیزییەکان بزانیت، زۆرجار دەتوانیت مەزەندە بکەیت پارچە کۆدێک چی دەکات، تەنانەت بە زمانێکیش کە هەرگیز فێری نەبوویت.
| Keyword | Everyday Englishواتای ڕۆژانە | What it does in codeلە کۆددا چی دەکات |
|---|---|---|
if | on condition thatئەگەر | runs a block only when a condition is trueبلۆکێک تەنها کاتێک جێبەجێ دەکات کە ڕاست بێت |
else | otherwiseئەگەرنا | runs another block when the condition is falseکاتێک هەڵە بێت بلۆکێکی تر جێبەجێ دەکات |
while | during the time thatهەتا، لە کاتێکدا | repeats a block as long as a condition is trueهەتا ڕاست بێت بلۆکێک دووبارە دەکاتەوە |
for | for each (value of a counter)بۆ هەر (نرخێکی ) | repeats a block a fixed number of timesبلۆکێک ژمارەیەکی دیاریکراو جار دووبارە دەکاتەوە |
return | give backگەڕاندنەوە | sends a value back from a function and ends itنرخێک لە دەگەڕێنێتەوە و کۆتایی پێ دەهێنێت |
true / false | correct / not correctڕاست / هەڵە | the two Boolean valuesدوو نرخەکەی |
Hear the English keywords of code used in real examples: if, else, while, for and functions, explained step by step.
کۆد بە ئینگلیزی و لە نموونەی ڕاستەقینەدا دەبیستیت: if، else، while، for و ، کە هەنگاو بە هەنگاو ڕوون دەکرێنەوە.
Watch 2:45–8:32: if, while, for and functions explained.
لە 2:45 تا 8:32 سەیر بکە: ڕوونکردنەوەی ، ، و .
Reading the English in codeخوێندنەوەی ئینگلیزیی ناو کۆد
A short program to read aloudبەرنامەیەکی کورت بۆ خوێندنەوە بە دەنگی بەرز
<?php
function hasPassed(int $mark): bool
{
if ($mark >= 50) {
return true;
} else {
return false;
}
}
$marks = [72, 45, 90];
for ($i = 0; $i < count($marks); $i++) {
if (hasPassed($marks[$i])) {
echo "Student " . ($i + 1) . ": passed<br>";
} else {
echo "Student " . ($i + 1) . ": failed<br>";
}
}
$seconds = 3;
while ($seconds > 0) {
echo $seconds . "... ";
$seconds--;
}
echo "Go!";Student 1: passed Student 2: failed Student 3: passed 3... 2... 1... Go!
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Student 1: passed<br>Student 2: failed<br>Student 3: passed<br>3... 2... 1... Go!Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
“function has passed”: it takes an
int(an integer, a whole number) and returns abool(a Boolean: true or false).function has passed:
intوەردەگرێت () وboolدەگەڕێنێتەوە (: true یان false).- Lineدێڕی 4-8
“If the mark is greater than or equal to fifty, return true. Else, return false.”
«ئەگەر نمرەکە گەورەتر یان یەکسان بێت بە پەنجا، true بگەڕێنەوە. ئەگەرنا، false بگەڕێنەوە.»
- Lineدێڕی 11
$marksis an array: a list of values.$marks[$i]means “element number i” (the index starts at 0).$marks: لیستێک لە .$marks[$i]واتە « ژمارە i» ( لە 0ـەوە دەست پێدەکات).- Lineدێڕی 12
“For i from zero, while i is less than the number of marks, add one to i.”
«بۆ i لە سفرەوە، هەتا i لە ژمارەی نمرەکان بچووکتر بێت، یەک بۆ i زیاد بکە.»
- Lineدێڕی 21-24
“While seconds is greater than zero, print seconds, then take one away.”
«هەتا seconds لە سفر گەورەتر بێت، seconds چاپ بکە، پاشان یەکی لێ کەم بکەرەوە.»
Reading the English in codeخوێندنەوەی ئینگلیزیی ناو کۆد
Saying operators in wordsخوێندنەوەی کارپێکەرەکان بە وشە
| Symbolهێما | Sayبڵێ | Meaningواتا |
|---|---|---|
== | is equal to | the same valueیەکسانە بە |
!= | is not equal to | a different valueیەکسان نییە بە |
< | is less than | smallerبچووکترە لە |
> | is greater than | biggerگەورەترە لە |
<= | is less than or equal to | smaller or the sameبچووکترە یان یەکسانە |
>= | is greater than or equal to | bigger or the sameگەورەترە یان یەکسانە |
&& / and | and | both must be trueهەردووکیان دەبێت ڕاست بن |
|| / or | or | at least one must be trueلانیکەم یەکێکیان دەبێت ڕاست بێت |
Listen: at the coding clubگوێ بگرە: لە یانەی کۆدنووسین
Hi, Aram! Is this the coding club?
سڵاو ئارام! ئەمە یانەی کۆدنووسینە؟
Yes, come in! Have you ever written a program?
بەڵێ، وەرە ژوورەوە! تا ئێستا نووسیوە؟
Only a little. I've made a simple web page with HTML, but I've never used a real programming language.
تەنها کەمێک. سادەم بە HTML دروست کردووە، بەڵام هەرگیز ڕاستەقینەم بەکارنەهێناوە.
Actually, HTML is a markup language, not a programming language. It describes a page, but it can't make decisions.
لە ڕاستیدا HTML ، نەک . لاپەڕەیەک وەسف دەکات، بەڵام ناتوانێت بڕیار بدات.
Oh, I see. So which language should I learn first?
ئا، تێگەیشتم. کەواتە سەرەتا فێری کام زمان ببم؟
I started with Python. It's a high-level language, so it's easy to read. Look at this line: if score > 50: print('Pass').
من بە Python دەستم پێکرد. ، بۆیە خوێندنەوەی ئاسانە. سەیری ئەم دێڕە بکە: if score > 50: print('Pass').
That's almost English! What happens when you run it?
ئەوە نزیکەی ئینگلیزییە! کاتێک کاری پێ دەکەیت چی ڕوو دەدات؟
The Python interpreter translates it and runs it step by step. In C, you have to compile the whole program first.
Python وەریدەگێڕێت و هەنگاو بە هەنگاو جێبەجێی دەکات. لە Cـدا دەبێت سەرەتا هەموو وەربگێڕیت.
And have you ever had a bug?
ئەی تا ئێستا تووشی بوویت؟
Hundreds! Last week my program ran without any error messages, but the answer was wrong. It was a logic error.
سەدان جار! هەفتەی ڕابردوو بەبێ هیچ کاری کرد، بەڵام وەڵامەکە هەڵە بوو. بوو.
How did you find it?
چۆن دۆزیتەوە؟
I did a dry run. I followed the code line by line with a pen and paper, and I found that I'd written “greater than” instead of “greater than or equal to”.
جێبەجێکردنێکی دەستیم کرد. بە قەڵەم و کاغەز دێڕ بە دێڕ بەدوای کۆدەکەدا چووم و بۆم دەرکەوت کە لە جیاتی «گەورەتر یان یەکسان» نووسیبووم «گەورەتر».
Great tip. Can I join the club?
ئامۆژگارییەکی باشە. دەتوانم بەشداری یانەکە بکەم؟
Of course! First, write an algorithm for something simple, like making tea. Then we'll turn it into code together.
بێگومان! سەرەتا بۆ شتێکی سادە بنووسە، وەک دروستکردنی چا. پاشان پێکەوە دەیکەین بە کۆد.
Interview a partner with the present perfect: Have you ever written a program? made a website? fixed a bug? used an IDE? When the answer is yes, ask a follow-up question in the past simple: What did it do? Which language did you use? How long did it take?
بە چاوپێکەوتن لەگەڵ هاوڕێیەکت بکە: Have you ever written a program? made a website? fixed a bug? used an IDE? کاتێک وەڵامەکە yes بوو، پرسیارێکی تر بە بکە: What did it do? Which language did you use? How long did it take?
Hintئاماژە
Notice the -ed sounds: used /d/, fixed /t/, created /ɪd/.
سەرنجی دەنگی -ed بدە: used /d/، fixed /t/، created /ɪd/.
Going further: precise programming English
- code is uncountable in programming: a lot of code, a line of code, a piece of code, never codes. A code is a secret number: a 2FA code, a discount code.
- run / execute / launch: run is everyday (run the program), execute is formal (the statement is executed), launch means start an app.
- Comparing: whereas, while and unlike show contrast. A compiler translates the whole program, whereas an interpreter translates it statement by statement. Unlike C, PHP does not produce an .exe file.
- Purpose: to + verb or in order to + verb, never for to: We use a flowchart to show the decisions.
- The real picture is mixed. Many languages use both methods: Java and Python first compile source code to bytecode, and then a virtual machine or interpreter runs it. PHP compiles each script to opcodes in memory before running them.
- Topic sentences: a good technical paragraph starts with one sentence that gives the main idea (There are two kinds of translator.). The next sentences give the major details, then the minor details and examples.
- Object-oriented programming (OOP): languages such as Java, C#, Python and PHP organise a program into objects made from classes (for example a Student class, and the object Shilan with her own name and marks). See Building software.
| Year | Event |
|---|---|
| 1957 | FORTRAN, one of the first high-level languages, was released by IBM. |
| 1959 | COBOL was designed for business programs. |
| 1972 | Dennis Ritchie created the C language at Bell Labs. |
| 1991 | Guido van Rossum released the first version of Python. |
| 1995 | Java, JavaScript and PHP all appeared in the same year. |
Say the -ed endings correctly: released /t/, designed /d/, created /ɪd/, appeared /d/, developed /t/. After /t/ or /d/ the ending is a full extra syllable /ɪd/.
Write pseudocode for an algorithm that inputs five marks and outputs their average. Use a FOR loop and a running total. Then describe it in three sentences.
Show answerوەڵامەکە پیشان بدە
total ← 0
FOR count ← 1 TO 5
INPUT mark
total ← total + mark
NEXT count
average ← total / 5
OUTPUT averageFirst, the algorithm sets the total to zero. Then it repeats two steps five times: it inputs a mark and adds it to the total. Finally, it divides the total by five and outputs the average.
هەڵە باوەکانی کوردزمانان
| هەڵە | ڕاست | ڕوونکردنەوە |
|---|---|---|
| I wrote many codes. | I wrote a lot of code. | لە code : a lot of code، a line of code. |
| If the mark will be 50, … | If the mark is 50, … | دوای if دێت، نەک will. |
| If is correct, shows “Welcome”. | If it is correct, it shows “Welcome”. | ئینگلیزی بکەری پێویستە: it. |
| We use a compiler for translate the code. | We use a compiler to translate the code. | بۆ مەبەست to + کار، نەک for. |
| The mark is greater from 50. | The mark is greater than 50. | بە کوردی «لە ٥٠ گەورەتر»، بەڵام لە ئینگلیزیدا than، نەک from. |
| language high-level, code source | high-level language, source code | ئاوەڵناو و ناوی یاریدەدەر پێش ناوی سەرەکی دێن، پێچەوانەی ئیزافەی کوردی (). |
| The program is compile. | The program is compiled. / The compiler compiles the program. | پێویستی بە هەیە: compiled. |
| I did a program. | I wrote (made, developed) a program. | لە ئینگلیزیدا write دەکرێت؛ do لەگەڵیدا نایەت. |
ئەم ڕستانە وەربگێڕە سەر ئینگلیزی:
- سەرەتا بنووسە، پاشان کۆدەکە.
- هەموو پێش کارکردن وەردەگێڕێت.
- ئەگەر نمرەکە لە ٥٠ کەمتر بێت، دەنووسێت «Fail».
- ئەم هەنگاوانە دووبارە دەکاتەوە تا PINـی دروست دەنووسێت.
- لە کۆدەکەمدا هەبوو.
Show answerوەڵامەکە پیشان بدە
- First write an algorithm, then the code.
- A compiler translates the whole program before it runs.
- If the mark is less than 50, the program prints “Fail”.
- The program repeats these steps until the user types the correct PIN.
- There was a logic error in my code.
هەڵە باوەکانی کوردزمانان
گۆکردن
- algorithm /ˈælɡərɪðəm/: فشار لەسەر بڕگەی یەکەمە و th دەنگی /ð/ـە (زمان لە نێوان ددانەکاندا)، نەک «ت» یان «س».
- pseudocode /ˈsjuːdəʊkəʊd/: پیتی p بێدەنگە: «سیوودۆکۆد».
- machine /məˈʃiːn/: ch وەک «ش» دەخوێندرێتەوە و فشار لەسەر بڕگەی دووەمە.
- compiler /kəmˈpaɪlə/، interpreter /ɪnˈtɜːprɪtə/، debug /diːˈbʌɡ/: فشار لەسەر بڕگەی دووەمە.
- کۆتایی -ed: compiled /d/، stopped /t/، executed /ɪd/. تەنها دوای t و d بڕگەیەکی زیادە دەخوێندرێتەوە.
هەڵە باوەکانی کوردزمانان
مێژوویەکی کورت: ڕابردووی سادە و بکەرنادیار
| ساڵ | ئینگلیزی | کوردی |
|---|---|---|
| 1957 | FORTRAN was released by IBM. | FORTRAN لەلایەن IBMـەوە بڵاو کرایەوە، یەکێک لە یەکەمین . |
| 1972 | Dennis Ritchie created the C language. | دێنیس ڕیچی زمانی Cـی دروست کرد. |
| 1991 | Python was first released. | یەکەم وەشانی Python بڵاو کرایەوە. |
| 1995 | Java, JavaScript and PHP appeared. | Java، JavaScript و PHP لە هەمان ساڵدا دەرکەوتن. |
Reviewپێداچوونەوە
What is the difference between pseudocode and a flowchart?جیاوازیی نێوان نیمچەکۆد و هێڵکاریی ڕەوت چییە؟
Both describe an algorithm. Pseudocode uses short English-like lines; a flowchart uses shapes and arrows.
هەردووکیان وەسف دەکەن. دێڕی کورتی وەک ئینگلیزی بەکاردەهێنێت؛ شێوە و تیر بەکاردەهێنێت.
Why do we need compilers and interpreters?بۆچی پێویستمان بە کۆمپایلەر و ئینتەرپرێتەر هەیە؟
Because people write in high-level languages, but the CPU only understands machine code. Compilers and interpreters translate between them.
چونکە خەڵک بە دەنووسن، بەڵام تەنها تێدەگات. و لە نێوانیاندا وەردەگێڕن.
Read this aloud: if ($age >= 18)ئەمە بە دەنگی بەرز بخوێنەوە: if ($age >= 18)
“If age is greater than or equal to eighteen…”
If age is greater than or equal to eighteen…
Which flowchart symbol is used for a decision?کام هێمای هێڵکاریی ڕەوت بۆ بڕیار بەکاردێت؟
A diamond. It has two ways out: yes and no.
چوارگۆشەی لار. دوو ڕێگای دەرچوونی هەیە: بەڵێ و نەخێر.
Videoڤیدیۆ
Watch a videoسەیری ڤیدیۆیەک بکە
A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
Learn what an algorithm is with an everyday counting example, how a loop repeats steps, and how to write the steps as pseudocode.
بە نموونەیەکی ڕۆژانەی ژماردن فێردەبیت چییە، چۆن هەنگاوەکان دووبارە دەکاتەوە و چۆن هەنگاوەکان وەک بنووسیت.
Whole video: what an algorithm is, with a loop and pseudocode.
هەموو ڤیدیۆکە: چییە، لەگەڵ و .
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Building Softwareدروستکردنی نەرمەواڵە
Related lecturesوانە پەیوەندیدارەکان
- Building Softwareدروستکردنی نەرمەواڵە
- Databases and Dataبنکەدراوەکان و دراوە
- Troubleshooting and the Help Deskچارەسەرکردنی کێشە و بەشی یارمەتی
- Introduction to PHPسەرەتایەک بۆ PHP
- PHP Syntax: Tags, Statements and Commentsداڕستنی PHP: تاگ، ڕستە و لێدوان
- Conditional Statements: if, else, elseif and switchڕستە مەرجییەکان: if و else و elseif و switch
- Loops: while, do...while, for, foreach, break and continueخولەکان: while و do...while و for و foreach و break و continue
- Functionsکردارەکان
- Operatorsکارپێکەرەکان
- What Is Programming?بەرنامەسازی چییە؟
- Programming Languagesزمانەکانی بەرنامەسازی
- Algorithms, Pseudocode and Flowchartsئەلگۆریزمەکان، نیمچەکۆد و هێڵکارییەکانی ڕەوت
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.