5 Questions
Дастурда қарор чiqarish uchun қандай талаблар ishlatiladi?
If-Else
Агар шарт пурқил ваqtida rost bo'lsa, нима амал бajariladi?
If блокida коди ижро ettiriladi
If-Else талаблари синтаксиси нима?
if (шарт) { амал }
Агар шарт пурқил ваqtida не rost bo'lsa, нима амал бajariladi?
Else блокida коди ижро ettiriladi
Нима мақсадда if-else талаблари ishlatiladi?
Қарор чiqarish uchun
Study Notes
Conditional Statements
If-Else Statements
- Used for decision-making in programs
- Syntax:
if (condition) { code to execute }
- If the condition is true, the code inside the if block is executed
- Optional
else
clause can be used to specify alternative code to execute if the condition is false - Example:
if (x > 5) {
cout << "x is greater than 5";
} else {
cout << "x is less than or equal to 5";
}
Loops
For Loops
- Used for repetitive tasks
- Syntax:
for (init; cond; increment) { code to execute }
- Initialization (init) is executed once at the beginning
- Condition (cond) is checked before each iteration
- Increment is executed at the end of each iteration
- Example:
for (int i = 0; i < 5; i++) {
cout << i << " ";
}
While Loops
- Used for repetitive tasks
- Syntax:
while (condition) { code to execute }
- Condition is checked before each iteration
- If the condition is true, the code inside the loop is executed
- Example:
int i = 0;
while (i < 5) {
cout << i << " ";
i++;
}
Do-While Loops
- Used for repetitive tasks
- Syntax:
do { code to execute } while (condition)
- Code inside the loop is executed at least once
- Condition is checked after each iteration
- Example:
int i = 0;
do {
cout << i << " ";
i++;
} while (i < 5);
Note: The main difference between while and do-while loops is that the code inside a do-while loop is executed at least once, even if the condition is false.
O'rganishda qaror qabul qilish va takrorlash uchun ishlatiladigan if-else statements va for, while, do-while loops haqida bilib olamiz.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free