c++ for loophaqida malumot

muhammadyusuf_b21347171bb

Muhammadyusuf

Posted on November 20, 2024

c++ for loophaqida malumot

for loop bu whlilega va do whilega oshqashnarsadir faqat u sinteks va yozilishi boshqacha

for (initialization; condition; increment) {
Enter fullscreen mode Exit fullscreen mode

shunday boladi

#include <iostream>
using namespace std;

int main() {
    for (int i = 0; i < 10; i++) {
        cout << "i ning qiymati: " << i << endl;
    }
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

bu qanday ishlaydi?
i ning qiymati: 0
i ning qiymati: 1
i ning qiymati: 2
i ning qiymati: 3
i ning qiymati: 4
i ning qiymati: 5
i ning qiymati: 6
i ning qiymati: 7
i ning qiymati: 8
i ning qiymati: 9
Qanday ishlaydi:

int i = 0; — i o‘zgaruvchisi 0 ga teng bo‘ldi.
i < 10; — Agar i 10 dan kichik bo‘lsa, tsikl ishlaydi.
cout << "i ning qiymati: " << i << endl; — Hozirgi i qiymatini chiqaradi.
i++ — bu koddan oldin

cout << "i ning qiymati: " << i << endl;
Enter fullscreen mode Exit fullscreen mode

shu kod ishlaydi va bundan kegin

i++;
Enter fullscreen mode Exit fullscreen mode

ishlaydi
agar siz forni shunday holatda korsangi
agar initialization; condition; incrementshular yoqbolsa

for(;;)
Enter fullscreen mode Exit fullscreen mode

shunday yoziladi

💖 💪 🙅 🚩
muhammadyusuf_b21347171bb
Muhammadyusuf

Posted on November 20, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related