Share c++ yes or no loop,

thaihoaaloha

New member
#C ++, #yesorNoloop, #C ++ lập trình

Một vòng có hoặc không là một loại vòng lặp kiểm tra một điều kiện và tiếp tục lặp hoặc thoát ra khỏi vòng lặp tùy thuộc vào kết quả của điều kiện.Loại vòng lặp này thường được sử dụng để lặp lại một bộ sưu tập các mục, lần lượt kiểm tra từng mục để xem nó có đáp ứng một tiêu chí nhất định không.

Cú pháp cho một vòng có hoặc không có trong C ++ như sau:

`` `
while (điều kiện) {
// mã sẽ được thực thi trong khi điều kiện là đúng
}
`` `

Trong đó `Điều kiện` là một biểu thức boolean đánh giá là đúng hoặc sai.Nếu điều kiện là đúng, mã bên trong vòng lặp sẽ được thực thi.Nếu điều kiện là sai, vòng lặp sẽ bị chấm dứt.

Ví dụ: mã sau sử dụng vòng lặp có hoặc không để lặp qua một vectơ chuỗi và in từng chuỗi vào bảng điều khiển:

`` `
#include <Istream>
#include <Vector>

sử dụng không gian tên STD;

int main () {
// Tạo một vectơ chuỗi
Vector <String> String = {"Hello", "World", "Goodbye"};

// lặp lại vectơ của chuỗi
for (chuỗi chuỗi: chuỗi) {
// In mỗi chuỗi vào bảng điều khiển
cout << chuỗi << endl;
}

trả lại 0;
}
`` `

## hashtags

* C ++
* Có hoặc không vòng lặp
* Lập trình C ++
* Câu điều kiện
* Kiểm soát dòng chảy
=======================================
#C++, #yesorNoloop, #C++Programming, #ConditionalStatements, #ControlFlow ## C++ Yes or no loop

A yes or no loop is a type of loop that checks a condition and either continues looping or breaks out of the loop depending on the result of the condition. This type of loop is often used to iterate over a collection of items, checking each item in turn to see if it meets a certain criteria.

The syntax for a yes or no loop in C++ is as follows:

```
while (condition) {
// code to be executed while the condition is true
}
```

where `condition` is a boolean expression that evaluates to either true or false. If the condition is true, the code inside the loop will be executed. If the condition is false, the loop will be terminated.

For example, the following code uses a yes or no loop to iterate over a vector of strings and print each string to the console:

```
#include <iostream>
#include <vector>

using namespace std;

int main() {
// create a vector of strings
vector<string> strings = {"hello", "world", "goodbye"};

// iterate over the vector of strings
for (string string : strings) {
// print each string to the console
cout << string << endl;
}

return 0;
}
```

## Hashtags

* C++
* Yes or no loop
* C++ programming
* Conditional statements
* Control flow
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top