Plan: 1 For repetition operator


Download 61.79 Kb.
bet1/4
Sana23.09.2023
Hajmi61.79 Kb.
#1686133
  1   2   3   4
Bog'liq
Mustaqil ishi


Working with examples reproducible process in C++.
Plan:
1 For repetition operator
2 Do … while iteration operator
3 While iteration operator

Depending on the problem to be solved, the programmer can use a repetition operator that is convenient for him.


The syntax of the for iteration operator is as follows:
for (; ; )
;
This operator starts the operation by performing . Then the repetition steps begin. At each step, is executed, if the result is different from 0 or true, the iteration body - is executed and finally is executed, otherwise control is passed from the iteration operator to the next operator. The iteration body can be a single operator, including an empty operator, or a block of operators.
The set of operators that must be performed during an iteration is called the iteration body. One or more operators can be used as the iteration body.
If we want to use more than one operator in the iteration body, we need to enclose these operators in block {}.
Example 1: A program that produces numbers from 1 to 10:

1 include
2 int main()
3 {
4 int i; 
5 for ( i= 1; i <= 10; i++)
6 cout << i << " ";
7 cout << endl;
8 system ("pause");
9 return 0;
10 }
The following result is displayed on the screen: The following for the iteration operator is given in detail.
The iteration operator for can be summarized as follows:
for (initial_value_of_the variable; repeat_condition;
increase the variable)
repetition _tanas i;
you can also reduce the variable instead of increase it.
If you want to use more than one operator in the iteration body, we need to put the operators between the block {} (begin and end).

Example 2: A program that produces numbers from 10 to 1:




Download 61.79 Kb.

Do'stlaringiz bilan baham:
  1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling