ASSIGMENT C++.
-
Upload
muzammir-azman -
Category
Documents
-
view
20 -
download
0
description
Transcript of ASSIGMENT C++.
7/17/2019 ASSIGMENT C++.
http://slidepdf.com/reader/full/assigment-c-568c6d4cc2108 1/4
ASSIGMENT C++
Bjarne Stroustrup
1.Go to
The goto statement unconditionally transfers control to the statement labeled by the
specied identier.
.!hile
The test of expression ta"es place before each e#ecution of the loop$ therefore%
a while loop e#ecutes &ero or more times. expression must be of an inte'ral type% a
pointer type% or a class type (ith an unambi'uous con)ersion to an inte'ral or pointer
type.
A while loop can also terminate (hen a brea"% 'oto% or return (ithin the statement body
is e#ecuted. *se continue to terminate the current iteration (ithout e#itin'
the while loop. continue passes control to the ne#t iteration of thewhile loop.
7/17/2019 ASSIGMENT C++.
http://slidepdf.com/reader/full/assigment-c-568c6d4cc2108 2/4
.,rea" and Continue
Break
Although you have already seen the break statement in the context of switchstatements, it deserves a fuller treatment since it can be used with other types of loops
as well. The break statement causes a do, for, switch, or while statement to terminate.
This includes the for each loops included in C++11.
Breaking a switch
n the context of a switch statement, a break is typically used at the end of each case to
signify the case is finished
Continue.
-orces transfer of control to the controllin' e#pression of the smallest enclosin' do% for%
or (hile loop.
.!hile True
I have seen this sort of thing used a lot, but I think it is rather strange... Wouldn't it be
much clearer to say(hile/true0, or something along those lines?
I'm guessing that (as is the reason for many-a-programmer to resort to cryptic code) this
is a tiny margin faster?
Why, and is itreally worth it? If so, why not just define it this way
5.Do/ While
The test of the termination condition is made after each e#ecution of the loop$ therefore%
a do-while loop e#ecutes one or more times% dependin' on the )alue of the termination
e#pression. The do-while statement can also terminate (hen a brea"% 'oto%
or return statement is e#ecuted (ithin the statement body.
The expression must ha)e arithmetic or pointer type. E#ecution proceeds as follo(s1
2. The statement body is e#ecuted.
7/17/2019 ASSIGMENT C++.
http://slidepdf.com/reader/full/assigment-c-568c6d4cc2108 3/4
. Ne#t% expression is e)aluated. If expression is false% the do-while statement
terminates and control passes to the ne#t statement in the pro'ram.
If expression is true /non&ero0% the process is repeated% be'innin' (ith step 2.
6.Jump / Loop
A C++ 3ump statement performs an immediate local transfer of control.
Loop
!xecute a se"uence of statements multiple times and abbreviates the code that
manages the loop variable.
#.if $ else
f
f the boolean expression evaluates to true, then the if block of code will be
executed, otherwise else block of code will be executed.
!lse
7/17/2019 ASSIGMENT C++.
http://slidepdf.com/reader/full/assigment-c-568c6d4cc2108 4/4
The else clause of an if...else statement is associated (ith the closest
pre)ious if statement in the same scope that does not ha)e a
correspondin' elsestatement.