Skip to content

Commit 06192e2

Browse files
committed
add more translations to part 2.2
1 parent 0a33cd4 commit 06192e2

File tree

1 file changed

+125
-109
lines changed

1 file changed

+125
-109
lines changed

data/osa-2/2-toistaminen.md

Lines changed: 125 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -226,264 +226,280 @@ while (true) {
226226
System.out.println("Done, thank you!");
227227
```
228228

229-
Ohjelman suoritus on esimerkiksi seuraavanlainen.
229+
<!-- Ohjelman suoritus on esimerkiksi seuraavanlainen. -->
230+
The output of the program is for example:
230231

231232
<sample-output>
232233

233-
Syötä luku, 0 lopettaa
234+
Input a number, 0 to quit
234235
**5**
235-
Syötit 5
236-
Syötä luku, 0 lopettaa
236+
You input 5
237+
Input a number, 0 to quit
237238
**-2**
238-
Syötit -2
239-
Syötä luku, 0 lopettaa
239+
You input -2
240+
Input a number, 0 to quit
240241
**0**
241-
Valmista, kiitos!
242+
Done, thank you!
242243

243244
</sample-output>
244245

245246
<programming-exercise name="Uudestaan" tmcname='osa02-Osa02_06.Uudestaan'>
246247

247-
Kirjoita edellä olevaa esimerkkiä mukaillen ohjelma, joka kysyy käyttäjältä lukuja kunnes käyttäjä syöttää luvun 4.
248+
<!-- Kirjoita edellä olevaa esimerkkiä mukaillen ohjelma, joka kysyy käyttäjältä lukuja kunnes käyttäjä syöttää luvun 4. -->
249+
Write a program by following an example that asks a user for numbers until user inputs number 4.
248250

249251
<sample-output>
250252

251-
Syötä luku
253+
Input a number
252254
**5**
253-
Syötä luku
255+
Input a number
254256
**744**
255-
Syötä luku
257+
Input a number
256258
**22**
257-
Syötä luku
259+
Input a number
258260
**-1**
259-
Syötä luku
261+
Input a number
260262
**4**
261263

262264
</sample-output>
263265

264266
</programming-exercise>
265267

266268

267-
## Toistolauseen alkuun palaaminen
269+
<!-- ## Toistolauseen alkuun palaaminen -->
270+
## Returning to the start of the loop
268271

269-
Toistolauseen alkuun palataan silloin kun suoritus päätyy toistolauseen lohkon loppuun eli kaikki toistolauseen lohkossa olevat komennot on suoritettu. Toistolauseen alkuun voi palata myös muualta kuin toistolauseen lopusta erillisellä `continue`-komennolla. Kun tietokone suorittaa komennon `continue`, siirtyy ohjelman suoritus toistolauseen alkuun.
272+
<!-- Toistolauseen alkuun palataan silloin kun suoritus päätyy toistolauseen lohkon loppuun eli kaikki toistolauseen lohkossa olevat komennot on suoritettu. Toistolauseen alkuun voi palata myös muualta kuin toistolauseen lopusta erillisellä `continue`-komennolla. Kun tietokone suorittaa komennon `continue`, siirtyy ohjelman suoritus toistolauseen alkuun. -->
273+
The beginning of the loop is returned to when the execution ends up in the end of the loop. This means that all the commands in the loop has been executed. You can also return to the beginning of the loop from other locations besides the end of the loop with command `continue`. When the computer executes command `continue`, the execution of the program moves to the beginning of the loop.
270274

271-
Alla olevassa esimerkissä esitellään `continue`-komennon käyttöä. Ohjelma pyytää käyttäjää syöttämään positiivisia lukuja. Mikäli käyttäjä syöttää negativiisen luvun tai nollan, ohjelma tulostaa viestin "Epäkelpo luku! Yritä uudelleen.", jonka jälkeen suoritus palaa toistolauseen alkuun. Edellisessä esimerkissä ohjelma lukee käyttäjältä merkkijonomuotoisia syötteitä. Vastaavanlaisen ohjelman toteutus onnistuu myös muilla muuttujatyypeillä. Alla olevassa esimerkissä käyttäjältä pyydetään lukuja kunnes käyttäjä syöttää luvun nolla.
275+
<!-- Alla olevassa esimerkissä esitellään `continue`-komennon käyttöä. Ohjelma pyytää käyttäjää syöttämään positiivisia lukuja. Mikäli käyttäjä syöttää negativiisen luvun tai nollan, ohjelma tulostaa viestin "Epäkelpo luku! Yritä uudelleen.", jonka jälkeen suoritus palaa toistolauseen alkuun. Edellisessä esimerkissä ohjelma lukee käyttäjältä merkkijonomuotoisia syötteitä. Vastaavanlaisen ohjelman toteutus onnistuu myös muilla muuttujatyypeillä. Alla olevassa esimerkissä käyttäjältä pyydetään lukuja kunnes käyttäjä syöttää luvun nolla. -->
276+
<!-- TODO epäkelpo = unfit? -->
277+
The example below showcases the usage of the command `continue`. The program asks a user to input a positive numbers. If the user inputs a negative number or a zero, the program prints a message "Unfit number, try again", after which the execution returns to the beginning of the loop. In the previous example, the program reads a string inputs from a user. Similar program with different input types is possible. In the example below the user is asked for numbers until the user inputs a zero.
272278

273279
```java
274-
Scanner lukija = new Scanner(System.in);
280+
Scanner scanner = new Scanner(System.in);
275281

276282
while (true) {
277-
System.out.println("Syötä positiivisia lukuja.");
278-
int luku = Integer.valueOf(lukija.nextLine());
283+
System.out.println("Insert positive integers");
284+
int number = Integer.valueOf(scanner.nextLine());
279285

280-
if (luku <= 0) {
281-
System.out.println("Epäkelpo luku! Yritä uudelleen.");
286+
if (number <= 0) {
287+
System.out.println("Unfit number! Try again.");
282288
continue;
283289
}
284290

285-
System.out.println("Syötit " + luku);
291+
System.out.println("Your input was " + number);
286292
}
287293
```
288294

289-
Ohjelman suoritus toistuu yllä olevassa esimerkissä ikuisesti, sillä toistolauseesta poistumiseen käytettävää `break`-komentoa ei ohjelmassa ole. Mikäli haluamme, että toistolauseesta voi poistua, tulee ohjelmaan lisätä `break`-komento.
295+
<!-- Ohjelman suoritus toistuu yllä olevassa esimerkissä ikuisesti, sillä toistolauseesta poistumiseen käytettävää `break`-komentoa ei ohjelmassa ole. Mikäli haluamme, että toistolauseesta voi poistua, tulee ohjelmaan lisätä `break`-komento. -->
296+
The execution of the program is repeated for ever in the example above because the `break` command,
297+
which exits the loop, is not used within the loop. In order to exit the loop, the `break` command must be added to the program.
290298

291-
Alla olevassa esimerkissä ohjelmaa on muokattu siten, että käyttäjältä pyydetään positiivisia lukuja. Mikäli käyttäjä syöttää negatiivisen luvun, kerrotaan että luku oli epäkelpo ja palataan toistolauseen alkuun. Mikäli käyttäjä syöttää nollan, toistolauseesta poistutaan.
299+
<!-- Alla olevassa esimerkissä ohjelmaa on muokattu siten, että käyttäjältä pyydetään positiivisia lukuja. Mikäli käyttäjä syöttää negatiivisen luvun, kerrotaan että luku oli epäkelpo ja palataan toistolauseen alkuun. Mikäli käyttäjä syöttää nollan, toistolauseesta poistutaan. -->
300+
In the example below, the program is modified in such a way that the user is asked to input positive numbers. If the user inputs a negative number, the program tells that the number was unfit and return to the beginning of the loop. If the number was a zero, the program exits the loop.
292301

293302
```java
294-
Scanner lukija = new Scanner(System.in);
303+
Scanner scanner = new Scanner(System.in);
295304

296305
while (true) {
297-
System.out.println("Syötä positiivisia lukuja.");
298-
int luku = Integer.valueOf(lukija.nextLine());
306+
System.out.println("Input positive numbers.");
307+
int number = Integer.valueOf(scanner.nextLine());
299308

300-
if (luku == 0) {
309+
if (number == 0) {
301310
break;
302311
}
303312

304-
if (luku < 0) {
305-
System.out.println("Epäkelpo luku! Yritä uudelleen.");
313+
if (number < 0) {
314+
System.out.println("Unfit number! Try again.");
306315
continue;
307316
}
308317

309-
System.out.println("Syötit " + luku);
318+
System.out.println("Your input was " + number);
310319
}
311320
```
312321

313322
TODO: tänne tarttee visualisoinnin
314-
323+
<!-- TODO: this requires a visualization -->
315324

316325
<quiznator id="5c1f6c8b64cf001162cb9790"></quiznator>
317326

318327
<programming-exercise name="Syötteiden rajaus" tmcname='osa02-Osa02_07.SyotteidenRajaus'>
319328

320-
Kirjoita ohjelma, joka kysyy käyttäjältä lukuja. Mikäli luku on negatiivinen (eli pienempi kuin nolla), käyttäjälle tulostetaan viesti "Epäkelpo luku" ja käyttäjältä kysytään uutta lukua. Jos taas luku on nolla, lukujen lukeminen lopetetaan ja ohjelma poistuu toistolauseesta. Mikäli luku on positiivinen, ohjelma tulostaa luvun toisen potenssin.
321-
329+
<!-- Kirjoita ohjelma, joka kysyy käyttäjältä lukuja. Mikäli luku on negatiivinen (eli pienempi kuin nolla), käyttäjälle tulostetaan viesti "Epäkelpo luku" ja käyttäjältä kysytään uutta lukua. Jos taas luku on nolla, lukujen lukeminen lopetetaan ja ohjelma poistuu toistolauseesta. Mikäli luku on positiivinen, ohjelma tulostaa luvun toisen potenssin. -->
330+
Write a program that asks a user for numbers. If the number is negaitve (smaller than zero) the program prints for user "unfit number" and asks user for a new number. If the number is zero, the program exits the loop. If the number is positive, the program prints the number power of two.
322331
<sample-output>
323332

324-
Syötä luku
333+
Input a number
325334
**5**
326335
25
327-
Syötä luku
336+
Input a number
328337
**4**
329338
16
330-
Syötä luku
339+
Input a number
331340
**-3**
332-
Epäkelpo luku
333-
Syötä luku
341+
Unfit number
342+
Input a number
334343
**1**
335344
1
336-
Syötä luku
345+
Input a number
337346
**0**
338347

339348
</sample-output>
340349

341350
</programming-exercise>
342351

343-
Edellisessä tehtävässä toteutettiin ohjelma, joka lukee käyttäjältä lukuja. Mikäli käyttäjä syöttää negatiivisen luvun, ohjelma ilmoittaa että luku oli epäkelpo, ja mikäli käyttäjä syöttää nollan, ohjelmasta poistutaan. Eräs ratkaisu tehtävään on seuraavanlainen.
352+
<!-- Edellisessä tehtävässä toteutettiin ohjelma, joka lukee käyttäjältä lukuja. Mikäli käyttäjä syöttää negatiivisen luvun, ohjelma ilmoittaa että luku oli epäkelpo, ja mikäli käyttäjä syöttää nollan, ohjelmasta poistutaan. Eräs ratkaisu tehtävään on seuraavanlainen. -->
353+
In the previous exercise a program was made that asks user for numbers. If the user did input a negative number, the program would infor that the number was unfit and if the user did input a zero, the program would have exited. A possible solution of the exercise is as follows
344354

345355
```java
346-
Scanner lukija = new Scanner(System.in);
356+
Scanner scanner = new Scanner(System.in);
347357

348358
while (true) {
349-
System.out.println("Syötä luku");
350-
int luku = Integer.valueOf(lukija.nextLine());
359+
System.out.println("Input a number");
360+
int number = Integer.valueOf(scanner.nextLine());
351361

352-
if (luku == 0) {
362+
if (number == 0) {
353363
break;
354364
}
355365

356-
if (luku < 0) {
357-
System.out.println("Epäkelpo luku");
366+
if (number < 0) {
367+
System.out.println("Unfit number");
358368
continue;
359369
}
360370

361-
System.out.println(luku * luku);
371+
System.out.println(number * number);
362372
}
363373
```
364374

365-
Ohjelman voisi toteuttaa myös muotoilemalla ehtolauseet toisella tavalla. Alla olevassa esimerkissä erillisten ehtolauseiden sijaan ehtolauseet on yhdistetty.
366-
375+
<!-- Ohjelman voisi toteuttaa myös muotoilemalla ehtolauseet toisella tavalla. Alla olevassa esimerkissä erillisten ehtolauseiden sijaan ehtolauseet on yhdistetty. -->
376+
Program could be made by modifying the if-statement to another form. In the example below; instead of the seperate if-statements, there's one if-statement.
367377
```java
368-
Scanner lukija = new Scanner(System.in);
378+
Scanner scanner = new Scanner(System.in);
369379

370380
while (true) {
371-
System.out.println("Syötä luku");
372-
int luku = Integer.valueOf(lukija.nextLine());
381+
System.out.println("Input a number");
382+
int number = Integer.valueOf(scanner.nextLine());
373383

374-
if (luku == 0) {
384+
if (number == 0) {
375385
break;
376-
} else if (luku < 0) {
377-
System.out.println("Epäkelpo luku");
386+
} else if (number < 0) {
387+
System.out.println("Unfit number");
378388
continue;
379389
}
380390

381-
System.out.println(luku * luku);
391+
System.out.println(number * number);
382392
}
383393
```
384394

385-
Kumpi edellä olevista vaihtoehdoista on selkeämpi?
395+
<!-- Kumpi edellä olevista vaihtoehdoista on selkeämpi? -->
396+
Which of the previous examples was more clear?
386397

387-
Tarkastellaan edellisten ohjelmien selkeyttä toisen esimerkin kautta. Alla oleva ohjelma kysyy käyttäjältä lukua. Mikäli luku on negatiivinen, käyttäjälle kerrotaan että luku on epäkelpo ja siirrytään toistolauseen alkuun. Mikäli luku on nolla, toistolauseesta poistutaan. Muissa tilanteissa käyttäjälle tulostetaan syötetyn luvun neliö, eli syötetty luku kerrottuna itsellään.
398+
<!-- Tarkastellaan edellisten ohjelmien selkeyttä toisen esimerkin kautta. Alla oleva ohjelma kysyy käyttäjältä lukua. Mikäli luku on negatiivinen, käyttäjälle kerrotaan että luku on epäkelpo ja siirrytään toistolauseen alkuun. Mikäli luku on nolla, toistolauseesta poistutaan. Muissa tilanteissa käyttäjälle tulostetaan syötetyn luvun neliö, eli syötetty luku kerrottuna itsellään. -->
399+
Let's examine the clarity of the previous programs through an example. Below, the program asks user for a number. If the number is negative, the user is informed that the number is unfit and the execution of the program goes to the beginning of the loop. If the number is zero, the program exits the loop. In other cases the program prints the square of the number, that is the number times itself.
388400

389401
```java
390-
Scanner lukija = new Scanner(System.in);
402+
Scanner scanner = new Scanner(System.in);
391403

392404
while (true) {
393-
System.out.println("Syötä luku ");
394-
int luku = Integer.valueOf(lukija.nextLine());
405+
System.out.println("Input a number ");
406+
int number = Integer.valueOf(scanner.nextLine());
395407

396-
if (luku < 0) {
397-
System.out.println("Epäkelpo luku");
408+
if (number < 0) {
409+
System.out.println("Unfit number");
398410
continue;
399411
}
400412

401-
if (luku == 0) {
413+
if (number == 0) {
402414
break;
403415
}
404416

405-
System.out.println(luku * luku);
417+
System.out.println(number * number);
406418
}
407419
```
408420

409-
Myös tämän ohjelman voi toteuttaa yhdistämällä ehtolauseet. Tällöin toteutus olisi seuraavanlainen.
421+
<!-- Myös tämän ohjelman voi toteuttaa yhdistämällä ehtolauseet. Tällöin toteutus olisi seuraavanlainen. -->
422+
This program can also be done by combining the if-statements. Here the implementations woud be the following.
410423

411424
```java
412-
Scanner lukija = new Scanner(System.in);
425+
Scanner scanner = new Scanner(System.in);
413426

414427
while (true) {
415-
System.out.println("Syötä luku ");
416-
int luku = Integer.valueOf(lukija.nextLine());
428+
System.out.println("Input a number ");
429+
int number = Integer.valueOf(scanner.nextLine());
417430

418-
if (luku < 0) {
419-
System.out.println("Epäkelpo luku");
420-
} else if (luku == 0) {
431+
if (number < 0) {
432+
System.out.println("Unfit number");
433+
} else if (number == 0) {
421434
break;
422435
} else {
423-
System.out.println(luku * luku);
436+
System.out.println(number * number);
424437
}
425438
}
426439
```
427440

428-
Tarkastellaan edellisiä ohjelmia kommentoituna. Jokaista palaa edeltää kommentit, jotka pyrkivät selittämään mitä ohjelmassa tapahtuu. Alla erillisillä ehtolauseilla toteutettu ohjelma.
441+
<!-- Tarkastellaan edellisiä ohjelmia kommentoituna. Jokaista palaa edeltää kommentit, jotka pyrkivät selittämään mitä ohjelmassa tapahtuu. Alla erillisillä ehtolauseilla toteutettu ohjelma. -->
442+
Let's examine the previous programs with comments. Before every command there's a comment that aims to explain what's happening in hte program. Below, a program done with seperate if-statements.
429443

430444
```java
431-
// Tehtävänä syötteen lukeminen käyttäjältä
432-
Scanner lukija = new Scanner(System.in);
445+
// The task is to read an input from the user //Tehtävänä syötteen lukeminen käyttäjältä
446+
Scanner scanner = new Scanner(System.in);
433447

434-
// Tehtävänä lohkon toistaminen kunnes lohkosta poistutaan
448+
// The task is to repeat the block until the block is exited//Tehtävänä lohkon toistaminen kunnes lohkosta poistutaan
435449
while (true) {
436-
// Tehtävänä luvun syöttämisen kehottaminen
437-
System.out.println("Syötä luku ");
438-
// Tehtävänä luvun lukeminen käyttäjältä
439-
int luku = Integer.valueOf(lukija.nextLine());
440-
441-
// Tehtävänä vartiointi, estetään epäkelpojen lukujen
442-
// jatkokäsittely
443-
if (luku < 0) {
444-
System.out.println("Epäkelpo luku");
450+
// The task is to ask user for an input //Tehtävänä luvun syöttämisen kehottaminen
451+
System.out.println("Input a number ");
452+
// The task is to read a number from the user //Tehtävänä luvun lukeminen käyttäjältä
453+
int number = Integer.valueOf(scanner.nextLine());
454+
455+
// The task is to guard and prevent unfit numbers// Tehtävänä vartiointi, estetään epäkelpojen lukujen
456+
// for further processing //jatkokäsittely
457+
if (number < 0) {
458+
System.out.println("Unfit number");
445459
continue;
446460
}
447461

448-
// Tehtävänä toistolauseesta poistumisen tarkastaminen
449-
if (luku == 0) {
462+
// The task is to check if the loop should be exited //Tehtävänä toistolauseesta poistumisen tarkastaminen
463+
if (number == 0) {
450464
break;
451465
}
452466

453-
// Tehtävänä syötetyn luvun neliön tulostaminen
454-
System.out.println(luku * luku);
467+
// The task is to print the square of the number //Tehtävänä syötetyn luvun neliön tulostaminen
468+
System.out.println(number * number);
455469
}
456470
```
457471

458-
Huomaat, että yllä jokaisella ehtolauseella on ohjelmassa yksi selkeä tehtävä.
472+
<!-- Huomaat, että yllä jokaisella ehtolauseella on ohjelmassa yksi selkeä tehtävä. -->
473+
Note that every if-statement has a one clear task.
459474

460-
Kun kommentoimme ohjelman, joka sisältää ehtolauseet yhdistettynä, kommentit ovat seuraavat.
475+
<!-- Kun kommentoimme ohjelman, joka sisältää ehtolauseet yhdistettynä, kommentit ovat seuraavat. -->
476+
When we comment the program that contains a combined if-statment, the comments are the following.
461477

462478
```java
463-
// Tehtävänä syötteen lukeminen käyttäjältä
464-
Scanner lukija = new Scanner(System.in);
479+
// The task is to read an input from the user // Tehtävänä syötteen lukeminen käyttäjältä
480+
Scanner scanner = new Scanner(System.in);
465481

466-
// Tehtävänä lohkon toistaminen kunnes lohkosta poistutaan
482+
// The task is to repeat the block until the block is exited// Tehtävänä lohkon toistaminen kunnes lohkosta poistutaan
467483
while (true) {
468-
// Tehtävänä luvun syöttämisen kehottaminen
469-
System.out.println("Syötä luku ");
470-
// Tehtävänä luvun lukeminen käyttäjältä
471-
int luku = Integer.valueOf(lukija.nextLine());
472-
473-
// if-else if-else -kokonaisuuden tehtävä?
474-
// Tehtävänä luvun käsittely?
475-
if (luku < 0) {
476-
System.out.println("Epäkelpo luku");
477-
} else if (luku == 0) {
484+
// The task is to ask user for an input // Tehtävänä luvun syöttämisen kehottaminen
485+
System.out.println("Input a number ");
486+
// The task is to read a number from the user //Tehtävänä luvun lukeminen käyttäjältä
487+
int number = Integer.valueOf(scanner.nextLine());
488+
489+
// The purpose of the if-else if-else block?//if-else if-else -kokonaisuuden tehtävä?
490+
// The task is the processing of the number?//Tehtävänä luvun käsittely?
491+
if (number < 0) {
492+
System.out.println("Unfit number");
493+
} else if (number == 0) {
478494
break;
479495
} else {
480-
System.out.println(luku * luku);
496+
System.out.println(number * number);
481497
}
482498
}
483499
```
484500

485-
Huomaamme, että `if-else if-else`-rakenteelle on vaikea määritellä yksi selkeä tehtävä. Ohjelmia suunniteltaessa ja toteuttaessa kannattaakin pyrkiä tilanteeseen, missä jokaisella ohjelman osalla on yksi selkeä tehtävä. Tämä teema tulee toistumaan kurssilla.
486-
501+
<!-- Huomaamme, että `if-else if-else`-rakenteelle on vaikea määritellä yksi selkeä tehtävä. Ohjelmia suunniteltaessa ja toteuttaessa kannattaakin pyrkiä tilanteeseen, missä jokaisella ohjelman osalla on yksi selkeä tehtävä. Tämä teema tulee toistumaan kurssilla. -->
502+
We realise, that for the `if-else if-else`-block it's hard to give on clear task. While designing a program, it is convenient to aim for a situation in which every part of the program has a clear task. This theme will be repeated throughout the course.
487503
TODO: quiz
488504

489505

0 commit comments

Comments
 (0)