Условный оператор. Циклы. (C-Sharp)

Материал из Информационная безопасностя
Перейти к навигации Перейти к поиску

Условный оператор

 1 Console.WriteLine("Please, enter your age:");
 2 string ageString = Console.ReadLine();
 3 int age = Convert.ToInt32(ageString);
 4 if (age > 65)
 5 {
 6     Console.WriteLine("Here is your pension.");
 7 }
 8 else
 9 {
10     Console.WriteLine("Good morning people!");
11 }
12 
13 switch (DateTime.Now.DayOfWeek)
14 {
15    case DayOfWeek.Sunday:
16    case DayOfWeek.Saturday:
17       Console.WriteLine("The weekend");
18       break;
19    case DayOfWeek.Monday:
20       Console.WriteLine("The first day of the work week.");
21       break;
22    case DayOfWeek.Friday:
23       Console.WriteLine("The last day of the work week.");
24       break;
25    default:
26       Console.WriteLine("The middle of the work week.");
27       break;
28 }

Циклы

 1 Console.WriteLine("while loop");
 2 i = 1;
 3 while (i < 11)
 4 {
 5     Console.WriteLine(i);
 6     i++;
 7 }
 8 
 9 Console.WriteLine("do while loop");
10 i = 1;
11 do
12 {
13     Console.WriteLine(i);
14     i++;
15 } while (i < 11);
16 
17 Console.WriteLine("for loop");
18 for (int j = 1; j < 11; j++)
19 {
20     Console.WriteLine(j);
21 }

Задачник