Студопедия
Случайная страница | ТОМ-1 | ТОМ-2 | ТОМ-3
АрхитектураБиологияГеографияДругоеИностранные языки
ИнформатикаИсторияКультураЛитератураМатематика
МедицинаМеханикаОбразованиеОхрана трудаПедагогика
ПолитикаПравоПрограммированиеПсихологияРелигия
СоциологияСпортСтроительствоФизикаФилософия
ФинансыХимияЭкологияЭкономикаЭлектроника

Continue Statement

Procedural programming | Object oriented programming | The return Statement | Creation and using one-dimensional and multi-dimensional arrays in the programming language Java. | Access labels | Classification of data types in the programming language Java. | Floating-point numbers |


Читайте также:
  1. A brief survey of control statements.
  2. A Decide which of these statements are true (T) or false (F).
  3. A. Decide whether each of the following statements is true or false. 1 страница
  4. A. Decide whether each of the following statements is true or false. 2 страница
  5. A. Decide whether each of the following statements is true or false. 3 страница
  6. A. Decide whether each of the following statements is true or false. 4 страница
  7. ACCOUNTING AND FINANCIAL STATEMENTS

It is sometimes desirable to skip some statements inside the loop. In such cases, continue statements are used.

for (condition)

{ if (condition2)

continue;

// statements;

 

 

26. Switch multi-branching construct in the programming language C++.

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.

Syntax:

The syntax for a switch statement in C++ is as follows:

switch(expression){ case constant-expression: statement(s); break; //optional case constant-expression: statement(s); break; //optional   // you can have any number of case statements. default: //Optional statement(s); }

The following rules apply to a switch statement:

 

 

27) Do while loop in the programming language C++.

In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. The while loop can be thought of as a repeating if statement.

The while construct consists of a block of code and a condition. The condition is evaluated, and if the condition is true, the code within the block is executed. This repeats until the condition becomes false. Because while loop checks the condition before the block is executed, the control structure is often also known as a pre-test loop. Compare with the do while loop, which tests the condition after the loop has executed.

For example, in the C programming language (as well as Java and C++, which use the same syntax in this case), the code fragment

int x = 0; while (x < 5)

{ printf ("x = %d \n ", x);(cout<<”x=”<<endl;) x++;}

The syntax for the do while control structure within the C++ programming language is:

do{ statement; statement; statement; statement; // This statement updates the flag;}while (expression);

EXAMPLE

do{ cout << "\nWhat is your age? ";

cin >> age_user; cout << "\nWhat is your friend's age? "; cin >> age_friend; cout >> "\nTogether your ages add up to: "; cout >> (age_user + age_friend); cout << "\nDo you want to do it again? y or n "; cin >> loop_response;} while (loop_response == 'y');

The three attributes of a test after loop are present. The action part consists of the 6 lines that prompt for data and then displays the total of the two ages. The update of the flag is the displaying the question and getting the answer for the variable loop_response. The test is the equality relational comparison of the value in the flag variable to the lower case character of y.

This type of loop control is called an event controlled loop. The flag updating is an event where someone decides if they want the loop to execute again.

28) Passing pointer and reference parameters to function in programming language C++.

A computer memory location has an address and a content. On the other hand, a variable is a named location that can store a value of a particular type. Typically, each address location can hold 8-bit (1-byte) of data. A 4-byte int value occupies 4 memory locations. A 32-bit system typically uses 32-bit addresses. To store a 32-bit address, 4 memory locations are required.

The following diagram illustrate the relationship between memory address and content; and variable's name, type and value.


Дата добавления: 2015-11-16; просмотров: 87 | Нарушение авторских прав


<== предыдущая страница | следующая страница ==>
Generics in the programming language Java.| Declaring Pointers

mybiblioteka.su - 2015-2024 год. (0.008 сек.)