DersTeders — ücretsiz, kurulum yok, her seviyede konu anlatımı ve sorular.

Programming Basics: reading and writing simple programs

A program is a list of precise instructions. Once you can read variables, conditions and loops, short programs stop looking mysterious.

2026-11-23

Variables as named boxes

A variable is a named place in memory that stores a value while the program runs. It can hold a number, a text or a logical value. A good name says what the value means, which makes the program easier to follow. Names usually cannot start with a digit or contain spaces. Assigning a new value replaces the old one, so the order of the lines matters: the computer follows the list from top to bottom.

Data types and why they matter

Numbers, text and logical values behave differently. Adding two numbers gives a number, while joining two texts gives a longer text. Confusing the two is a classic source of strange output: a digit stored as text may be appended instead of added. Conversion must be explicit. Knowing the type of each value also tells you which operations make sense, such as comparing two numbers or checking whether a text is empty.

Conditions make decisions

A condition is a statement that is either true or false. If it is true, one block of code runs; otherwise another block runs. Comparisons such as greater than or equal to, plus logical operators like and / or, let you express more than one requirement. Write the condition in words before coding it: if the counter has passed the limit, stop. That sentence usually maps directly to a single line of code.

Loops repeat without copying code

A loop runs the same block several times. A counted loop repeats a known number of times; a while loop continues as long as a condition stays true. Each pass should change something the condition depends on, otherwise the loop never ends. For example, starting from zero and adding 1, 2, 3, 4 and 5 gives a total of 15. The loop does the same five additions without five separate lines.

Tracing a short program by hand

Take a counter that starts at 2, increases by 3 each step and stops once it passes 10. The values printed are 2, 5 and 8; the next value is 11, which is above the limit, so the loop stops before printing it. Tracing a program on paper with a small table of variable values is the fastest way to find a logic error. It also trains you to predict the output before you run the code.

Common mistakes to avoid

Forgetting to update the loop variable creates an endless loop. Starting a running total at the wrong value shifts every later result. Using a text where a number is expected produces concatenation instead of addition. Misplaced or missing braces change which lines belong to a condition. And a condition written with assignment instead of comparison silently changes a value. Test with tiny inputs where you can check the answer mentally before trusting a larger case.

Frequently asked questions

What is the difference between a variable and a constant?

A variable can be assigned a new value during the run; a constant keeps the value it was given. Use a constant for values that should never change, such as a fixed limit.

Why does my loop never stop?

Because the condition depends on a value that the loop never changes. Make sure each pass updates that value and that the condition can eventually become false.

How can I check a program without running it?

Trace it on paper: write the variable names in a table and update them line by line. With small numbers you can predict the exact output and then compare it with the real run.

Create a free account — save your progress

Save your notes

Keep learning