Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //using System.Threading.Tasks;
  6.  
  7. namespace Looppaaminen
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. // while -luupin rakenne , alkuehtoinen
  14. //
  15. // Kysy tieto
  16. // While (ehto on tosi)
  17. // {
  18. // ... toiminnot
  19. // kysy tietoa uudelleen, liittyy ehtoon.
  20. // }
  21.  
  22. int i; // kierroslaskuri
  23. int n; // Kysy käyttäjältä kierrosten lkm
  24. string luku;
  25.  
  26. Console.WriteLine("Anna kierrosten lkm");
  27. luku = Console.ReadLine();
  28. int.TryParse(luku, out n);
  29.  
  30. i = 0; //kysytieto
  31. while (i < n) // Looppaa niin kauan kuin ehto on tosi eli pienempi kuin N TAI kiertää niin monta kertaa kuin annettu N
  32. {
  33. i = i + 1; // "Kysy tietoa!" TAI n++;
  34. // Toiminnot
  35. Console.WriteLine("Kierros numero:{0}", i);
  36. }
  37. Console.WriteLine("");
  38.  
  39. while (n > 0)
  40. {
  41. Console.WriteLine("Kierros nro: {0}", n);
  42. n = n - 1; //TAI n--;
  43. }
  44. Console.WriteLine("\n loppaus for-rakenteella.\n");
  45. for (i = 0; i < 3; i++) //for looppi, lukumääräinen toistolause jota käytetään tyypillisesti taulukoiden kanssa.
  46. {
  47. Console.WriteLine("Kierros numero: {0}", i + 1);
  48. }
  49. Console.ReadLine();
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement