ج ++ لـ (int i = 0؛ i <= 1000؛ i ++) { cout <<i<<endl؛}
``When you execute this code in a c++ program numbers from 1 to 1000 will be printed.
Now lets discuss how the for loop works.
* You start a for loop by typing the keyword 'for'. It means you are starting a for loop
` for `
* Next you open and close a round bracket. In this brackets you write some conditions which will be discussed later
` for()`
* Inside the brackets first you write the initial condition ie the value from where the loop will start. Like in the
above program we write int i = 0
` for(int i = 0)`
* Then you write the semicolon and then condition until when the loop will be executed. In the above code you define
i <1000.Itmeansuntilvalueofiislessthen1000execuetetheloop.
` for(int i=0;i<=1000) `
* Then you define the incremented value that is how much i has to be incremented in each iteration. In the above code
we write i++. It means value of i will be incremented by 1 every time.
` for(int i=0;i<=1000;i++) `
* If there is only one statement inside the loop then the curly bracket is optional but its better to write loop code
within brackets so that you don't get confused.
``` c++
for(int i=0;i<=1000;i++)
{
}
```
* Then inside the loop you write what do you want to do. In the above program we output the value of i.
So, in this way the for loop works
If you want to print even numbers from 1 to 1000 then your program will look like this
``
ج ++ لـ (int i = 0؛ i = 1000 = i = i + 2) { cout <<i<<endl؛}
\`\` \`
* الفرق في البرنامج الأول والثاني هو جزء الزيادة. بقية الكود هو نفسه. هذا البرنامج سوف يطبع 0 و ثم إضافة 2 إليه وطباعة 2 على وحدة التحكم وهكذا تصبح قيمة up تساوي 1000.
برنامجنا النهائي لطباعة حتى الأرقام من 0 إلى 1000 سيبدو هكذا.
\`\` \`ج + +
# تتضمن
استخدام اسم للمحطة؛ انت مين() { لـ (int i = 0؛ i = 1000 = i = i + 2) { cout <<i<<endl؛}العودة0} \`\` \`