freeCodeCamp/guide/russian/cplusplus/range-for-loop/index.md

30 lines
777 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Range For Loop
localeTitle: Диапазон для цикла
---
## Диапазон для цикла
Цикл, основанный `for` диапазоне, позволяет легко выполнять цикл по целому ряду элементов (например, элементов в контейнере).
С традиционным `for` цикла:
```cpp
std::vector<std::string> stringList {"one", "two", "three"};
for (size_t il; il < stringList.size(); il++
{
std::cout << stringList.at(il) << std::endl;
}
```
С диапазоном `for` цикла:
```cpp
std::vector<std::string> stringList {"one", "two", "three"};
for (auto& singleString : stringList)
{
std:cout << singleString << std::endl;
}
```