1/27
Looks like no tags are added yet.
Name  | Mastery  | Learn  | Test  | Matching  | Spaced  | 
|---|
No study sessions yet.
Control statements
statements that alter the sequence of flow of instructions.
simple statement
Any single input statement, assignment and output statement is
a block or compound statement
A group of statement that are separated by semicolon and enclosed within curled braces { and } is called a
flow of control
The order in which statements are executed in a program is called
Selection statements
Iteration statements
C++ supports two basic control statements
Selection Statements
This statement allows us to select a statement or set of statements for execution based on some condition.
Selection Statements
also known as conditional statement
if statement
if – else statement
Nested – if statement
switch statement
The different selection statements
if statement
This is the simplest form of if statement,also called as one-way branching.
if – else statement
This structure helps to decide whether a set of statements should be executed or another set of statements should be executed.This statement is also called as two-way branching.
Nested if statement
If the statement of an if statement is another if statement then such an if statement is called as. t contains an if statement within another if statement.
if – else - if statement
This structure helps the programmer to decide the execution of a statement from multiple statements based on a condition.This statement is also called as multiple-way branch.
Switch Statement
C++ has built in multiple-branch selection statement.If there are more than two alternatives to be selected, multiple selection construct is used.is a bit peculiar within the C++ language because it uses labels instead of blocks
Iterative Constructs or Looping
are the statements that are used to repeatedly execute a sequence of statements until some condition is satisfied or a given number of times.
while loop
do while loop
for loop
three types of looping structures in C++.
while loop
This structure checks the condition at the beginning of the structure.The set of statements are executed again and again until the condition is true.
do while statements
This is a post-tested loop structure. This structure checks the condition at the end of the structure. The set of statements are executed again and again until the condition is true.
while: pre- tested looping structure, Minimum execution of loop is zero. Semi colon is not used.
do while: post tested looping structure,Minimum execution of loop is once. Semi colon is used.
Difference between while and do while loop:
for statement
is the fixed execution structure. This structure is usually used when we know in advance exactly how many times asset of statements is to be repeatedly executed again and again. This structure can be used as increment looping or decrement looping structure.
Jump statements or Transfer of control from within loop
Terminate the execution of loop.
Exiting a loop.
Half way through to skip the loop. All these can be done by using break, exit and continue statements.
break statement
You can use it to terminate a case in the switch statement.
You can also use it to force immediate termination of a loop like while, do-while and for, by passing the normal loop conditional test.
When encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement.
exit( ) function
This function causes immediate termination of the entire program, forcing a return to the operating system. In effect, acts as if it were breaking out of the entire program.
return code
is used by the operating system and may be used by calling programs.
exit code of 0
means that the program finished normally and any other value means that some error or unexpected results happened.
continue statement
causes the program to skip the rest of the loop in the current iteration as if end of the statement block has been reached, causing it to jump to start of the following iteration.works somewhat like break statement.
goto statement
allows to makes an absolute jump to another point in the program. This statement execution causes an unconditional jump or transfer of control from one statement to the other statement with in a program ignoring any type of nesting limitations.
label
The destination is identified by a__which is then used as an argument for the goto statement.
colon
A label is made of a valid identifier followed by a