The то loop, шикастан and давом
In this lesson: you will write a loop when you do not know in advance how many steps it will make.
Lesson 11
то loop, шикастан and давомто loop, шикастан and давомIn this lesson: you will write a loop when you do not know in advance how many steps it will make.
то loop, шикастан and давомIn this lesson: you will write a loop when you do not know in advance how many steps it will make.
тото (condition) { … } ("while") repeats the commands while the condition is дуруст:
1тағ шумора = 5;2то (шумора > 0) {3чоп(шумора);4шумора = шумора - 1;5}6чоп("Оғоз!");
Something must change inside the loop, so that one day the condition becomes нодуруст. Otherwise the loop never ends.
1тағ адад = хонданиРақам();2тағ шумора = 0;3то (адад > 0) {4адад = Риёзӣ.поён(адад / 10);5шумора++;6}7чоп("Рақамҳо:", шумора);
2026
шикастан: leaving the loop1// Reads numbers until 0 and prints their sum2тағ ҷамъ = 0;3то (дуруст) {4тағ рақам = хонданиРақам();5агар (рақам === 0) {6шикастан;7}8ҷамъ += рақам;9}10чоп("Ҷамъ:", ҷамъ);
5 3 8 0
то (дуруст): this loop never ends by itself. You leave it with шикастан ("break").давом ("continue") ends the current step and goes on to the next one.Read a positive whole number and print how many digits it has.
Input: One positive number.
Output: The number of digits.
Read a positive whole number and print its digits in reverse order: from 123 you get 321, from 1200 you get 21.
Input: One positive number.
Output: The reversed number.
Read numbers one at a time until a 0 comes. Print the sum of all the numbers.
Input: Numbers, each on a separate line; the last one is 0.
Output: The sum.