Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- //using System.Threading.Tasks;
- namespace Looppaaminen
- {
- class Program
- {
- static void Main(string[] args)
- {
- // while -luupin rakenne , alkuehtoinen
- //
- // Kysy tieto
- // While (ehto on tosi)
- // {
- // ... toiminnot
- // kysy tietoa uudelleen, liittyy ehtoon.
- // }
- int i; // kierroslaskuri
- int n; // Kysy käyttäjältä kierrosten lkm
- string luku;
- Console.WriteLine("Anna kierrosten lkm");
- luku = Console.ReadLine();
- int.TryParse(luku, out n);
- i = 0; //kysytieto
- while (i < n) // Looppaa niin kauan kuin ehto on tosi eli pienempi kuin N TAI kiertää niin monta kertaa kuin annettu N
- {
- i = i + 1; // "Kysy tietoa!" TAI n++;
- // Toiminnot
- Console.WriteLine("Kierros numero:{0}", i);
- }
- Console.WriteLine("");
- while (n > 0)
- {
- Console.WriteLine("Kierros nro: {0}", n);
- n = n - 1; //TAI n--;
- }
- Console.WriteLine("\n loppaus for-rakenteella.\n");
- for (i = 0; i < 3; i++) //for looppi, lukumääräinen toistolause jota käytetään tyypillisesti taulukoiden kanssa.
- {
- Console.WriteLine("Kierros numero: {0}", i + 1);
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement