Циклы. (C++): различия между версиями
Перейти к навигации
Перейти к поиску
(Новая страница: «== Условный оператор == <syntaxhighlight lang="C++" line> int age; std::cout << "Please enter your age:"; std::cin >> age; if (age > 65) { std...») |
|||
| Строка 1: | Строка 1: | ||
| − | == | + | == Циклы == |
<syntaxhighlight lang="C++" line> | <syntaxhighlight lang="C++" line> | ||
| − | + | std::cout << "while loop" << std::endl; | |
| − | std::cout << " | + | int i = 1; |
| − | std:: | + | while (i < 11) |
| − | |||
{ | { | ||
| − | std::cout << | + | std::cout << i << std::endl; |
| + | i++; | ||
} | } | ||
| − | + | ||
| + | std::cout << "do while loop" << std::endl; | ||
| + | i = 1; | ||
| + | do | ||
{ | { | ||
| − | std::cout << " | + | std::cout << i << std::endl; |
| + | i++; | ||
| + | } while (i < 11); | ||
| + | |||
| + | printf("for loop\n"); | ||
| + | for (int j = 1; j < 11; j++) | ||
| + | { | ||
| + | std::cout << j << std::endl; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Текущая версия на 11:11, 1 июля 2022
Циклы
1 std::cout << "while loop" << std::endl;
2 int i = 1;
3 while (i < 11)
4 {
5 std::cout << i << std::endl;
6 i++;
7 }
8
9 std::cout << "do while loop" << std::endl;
10 i = 1;
11 do
12 {
13 std::cout << i << std::endl;
14 i++;
15 } while (i < 11);
16
17 printf("for loop\n");
18 for (int j = 1; j < 11; j++)
19 {
20 std::cout << j << std::endl;
21 }