���� �� ��� ������� �� ��������
����������� �� ���������� II ���� (Advanced Decisions)
..
(������� � ��������)
.
(����������)

A. ������ �� ��������� break �  ����� ���������. ������� ��� ��-���� � ��������������� ������ ��� ���� ���������� break �� �� ������ � ���� �����������, j = n;, ����� ���������� ������������ �� ������. �� ��������, ��� ���� ���� ����������, ���� �� ����� ��������� ��������, � ��� ���� ��-���������� ��������, ���� ����������� �� �������� ����� �����������, ���� � ��������� � ��� �� �� ������� ���� ������.

������ � ���������� �� ��������� break:

 // usage of break statement
 int isPrime = 1;               // assume n is prime
 for(int j = 2; j < n/2; j++)   // divide by all integers from 2 to n/2
 {
   if (n%j == 0)                // if evenly divisible,
   {
     isPrime = 0;               // n is not a prime
     break;                     // no point in looping again
    }
 }

���� ����� �������� ������ - ������ �� ��������� break:

 // usage of if-else construction
 int isPrime = 1;               // assume n is prime
 for(int j = 2; j < n/2; j++)   // divide by all integers from 2 to n/2
 {
   if (n%j == 0)                // if evenly divisible,
   {
     isPrime = 0;               // n is not a prime
     j = n;                     // increase j not the cycle to be repeated
    }
 }

B. ������ �� ��������� continue �  ����� ���������. ������� ��� ��-���� � ��������������� ������ ��� ���� ���������� continue �� �� ������ � ������������� if-else. �� ��������, � ����� ���� �� ����������, �� ��� ������ �� ���������� � ���������� ��� ��������� cout << "\nDo another (y/n)? "; cin >> ch;.

������ � ���������� �� ��������� continue:

  float dividend, divisor;
  char ch;
  do
  {
    cout << "Enter dividend: ";
    cin >> dividend;
    cout << "Enter divisor: ";
    cin >> divisor;
    if (divisor == 0)                       // if user error,
    {
      cout << "Divisor can't be zero\n";
      continue;                             // go back to top of loop
    }
    cout << "Quotient is " << dividend / divisor;
    cout << "\nDo another (y/n)? ";
    cin >> ch;
  } while(ch != 'n');

������ � ���������� �� ������������� if-else:

  float dividend, divisor;
  char ch;
  do
  {
    cout << "Enter dividend: ";
    cin >> dividend;
    cout << "Enter divisor: ";
    cin >> divisor;

    if (divisor == 0)                        // if user error,
       cout << "Divisor can't be zero\n";
    else                                     // else calculate the quotient,
      cout << "Quotient is " << dividend / divisor;

    cout << "\nDo another (y/n)? ";
    cin >> ch;
  } while(ch != 'n');

(������� � ��������)

(����������)

����������

[1] Robert Lafore; C++ Interactive Course. Waite Group Press, Macmillan Computer Publishing, 1996.

�����: ����. �������� �����������

[ ���� � �������� �� ���� 15 �� ������ 2008 �. �� �������� "������" www.kosnos.com ]

Keywords: �++,  OOP programming , C++ , Classes , Inheritance , Reusability , Creating New Data Types , Polymorphism and Overloading
������� ����: ���� , �����, ������� ����������� ������������ , ������������