Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1.3.8.3 Подумайте когда лучше использовать цикл for а когда while. И приведите наилучший пример использования того и того цикла.
- public static void Main(string[] args)
- {
- OptimalCycleFor();
- Console.ReadKey();
- OptimalCycleWhile();
- Console.ReadKey();
- }
- static void OptimalCycleWhile()
- {
- int countUser;
- int trueCount = 4;
- do
- {
- Console.Clear();
- Console.WriteLine("Сколько будет: 2 * 2 ?");
- }
- while(int.TryParse(Console.ReadLine(), out countUser) != true || countUser != trueCount);
- }
- static void OptimalCycleFor()
- {
- Console.WriteLine("Введите целое число.");
- int countUser;
- if(int.TryParse(Console.ReadLine(), out countUser) == false)
- {
- return;
- }
- int sum = 0;
- for(int i = 1; i <= countUser; i++)
- {
- sum += i;
- }
- Console.WriteLine("Сумма всех чисел: {0}", sum);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement