Professional Documents
Culture Documents
Bjarne stroustrup is the person who written the C++. He was born on 30
December 1950 and he is the computer scientist. His most notable for
the creation and development is the C++ programming that is widely used
now. He is a Distinguished Research Professor and holds the College of
Engineering Chair in Computer Science at Texas A&M University. He is
also a visiting professor at Columbia University and works at Morgan
Stanley.
b) While
A while loop statement repeatedly executes a target statement as
long as a given condition is true. Here, statement(s) may be a
single statement or a block of statements. The condition may be
any expression, and true is any non-zero value. The loop iterates
while the condition is true. When the condition becomes false,
program control passes to the line immediately following the loop.
Example:
#include <iostream>
using namespace std;
int main ()
{
// Local variable declaration:
int a = 10;
return 0;
}
d) While True
This is commonly called "infinite loop". Yet it is not technically
infinite - it will stop once control flows through break.
Example:
.section __TEXT,__text,regular,pure_instructions
.globl _main
.align 4, 0x90
_main:
## @main
.cfi_startproc
## BB#0:
pushq %rbp
Ltmp2:
.cfi_def_cfa_offset 16
Ltmp3:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp4:
.cfi_def_cfa_register %rbp
movl $0, -4(%rbp)
LBB0_1:
## =>This Inner Loop Header: Depth=1
jmp LBB0_2
LBB0_2:
## in Loop: Header=BB0_1 Depth=1
movb $1, %al
testb $1, %al
jne LBB0_1
jmp LBB0_3
LBB0_3:
movl $0, %eax
popq %rbp
ret
.cfi_endproc
e) Do / While
The test of the termination condition is made after each
execution of the loop; therefore, a do-while loop executes one or
more times, depending on the value of the termination expression.
The do-while statement can also terminate when a break, go to,
or return statement is executed within the statement body.
Example:
#include <iostream>
using namespace std;
int main ()
{
// Local variable declaration:
int a = 10;
// do loop execution
do
{
cout << "value of a: " << a << endl;
a = a + 1;
}while( a < 20 );
return 0;
}
f) Jump / loop
A C++ jump statement performs an immediate local transfer of
control. Use the for statement to construct loops that must
execute a specified number of times. The for statement consists
of three optional parts that is (init-expression, cond-expression
and loop-expression)
Example:
#include <stdio.h>
int main()
{
int i = 0;
do
{
i++;
printf_s("before the continue\n");
continue;
printf("after the continue, should never print\n");
} while (i < 3);
printf_s("after the do loop\n");
}
g) If / else
The value of expression is nonzero, statement1 is executed. If the
optional else is present, statement2 is executed if the value
of expression is zero. Expression must be of arithmetic or pointer
type, or it must be of a class type that defines an unambiguous
conversion to an arithmetic or pointer type. (For information about
conversions, see Standard Conversions.)In both forms of
the if statement, expression, which can have any value except a