// program control_structures (input, output);

Pascal and Python through the
three control structures

Every program is built from just three ways of organising steps — running them in order, choosing between them, and repeating them. This lab pairs each idea with its flowchart, its pseudocode, and the same algorithm written in both Pascal and Python — edit and run either one right here. Once you can read a flowchart, the programming language is just spelling.

සෑම ක්‍රමලේඛයක්ම ගොඩනැඟෙන්නේ පියවර සංවිධානය කරන ක්‍රම තුනකිනි — පිළිවෙළට ක්‍රියාත්මක කිරීම (අනුක්‍රමය), තේරීම, සහ පුනරාවර්තනය. මෙම පාඩමේ එක් එක් සංකල්පය සඳහා flow chart එක, pseudo code එක සහ ඔබට මෙහිදීම සංස්කරණය කර ක්‍රියාත්මක කළ හැකි සැබෑ Pascal කේතය ඇත.

1 Sequence · අනුක්‍රමය 2 Selection · තේරීම 3 Repetition · පුනරාවර්තනය Flowchart + Pseudocode + Pascal
▸
How each example works. Open the tabs to compare the flowchart, pseudocode, Python code and Pascal code. Both code panes are editable — change them however you like. Type the values the program asks for into the Input box (one per line or separated by spaces), then press Run. The Run button executes whichever language tab you picked last (Python by default).
එක් එක් උදාහරණය flowchart, pseudo code සහ Pascal කේතය ලෙස tab තුළ ඇත. Pascal කොටස සංස්කරණය කළ හැකිය. ක්‍රමලේඛය ඉල්ලන අගයන් Input කොටුවට ඇතුළත් කර (පේළියකට එකක් හෝ හිස්තැන් වලින් වෙන් කර) Run program ඔබන්න.
1

Sequence · අනුක්‍රමය

In a sequence, the steps run one after another from beginning to end, in a fixed order. Nothing is skipped and nothing repeats — the computer simply does step 1, then step 2, then step 3.

අනුක්‍රමයකදී පියවර ආරම්භයේ සිට අවසානය දක්වා නියමිත පිළිවෙළට එකින් එක ක්‍රියාත්මක වේ. කිසිවක් මඟ හරින්නේ හෝ පුනරාවර්තනය වන්නේ නැත — පරිගණකය පියවර 1, ඉන්පසු 2, ඉන්පසු 3 ලෙස කරගෙන යයි.

2

Selection · තේරීම

In a selection, the program checks a condition. If it is true, one set of steps runs; if it is false, a different set (or none) runs. This is how a program makes decisions.

තේරීමකදී ක්‍රමලේඛය කොන්දේසියක් පරීක්ෂා කරයි. එය සත්‍ය නම් එක් පියවර කට්ටලයක්ද, අසත්‍ය නම් වෙනත් කට්ටලයක් (හෝ කිසිවක් නැත) ක්‍රියාත්මක වේ. ක්‍රමලේඛයක් තීරණ ගන්නේ මෙලෙසය.

3

Repetition · පුනරාවර්තනය

In repetition (a loop), one or more steps are repeated until a condition is met. Use FOR when you know how many times in advance, and WHILE / REPEAT when you do not.

පුනරාවර්තනයකදී (loop) කොන්දේසියක් සපුරන තුරු එක් හෝ කිහිප පියවරක් නැවත නැවත කරයි. වාර ගණන කලින් දන්නා විට FOR ද, නොදන්නා විට WHILE / REPEAT ද භාවිතා කරන්න.

4

Arrays · අරාව

An array stores many values of the same type under one name, reached by an index in square brackets — marks[0], marks[1], … Arrays and the FOR loop work together perfectly: the loop variable becomes the index.

අරාවක් එකම නමක් යටතේ එකම වර්ගයේ අගයන් රාශියක් ගබඩා කරයි. ඒවාට වරහන් තුළ දර්ශකයකින් ළඟා වේ — marks[0], marks[1], … අරා සහ FOR loop එකට හොඳින් ක්‍රියා කරයි: loop විචල්‍යය දර්ශකය බවට පත් වේ.

+

Putting it together · එකට යෙදීම

Real programs combine all three. Here a selection sits inside a repetition: a loop reads ten numbers, and for each one it decides odd or even, counting them separately.

සැබෑ ක්‍රමලේඛ මේ තුනම ඒකාබද්ධ කරයි. මෙහිදී තේරීමක් පුනරාවර්තනයක් ඇතුළත ඇත: loop එකක් සංඛ්‍යා දහයක් කියවා, එක් එක් සංඛ්‍යාව ඔත්තේ ද ඉරට්ටේ ද යන්න තීරණය කර වෙන වෙනම ගණන් කරයි.