Jump to content

Intro To C++/Making '''''statement'''''

From Wikibooks, open books for an open world

Controlling with if and else

[edit | edit source]

The C++ if keyword performs the basic conditional test. If something is true, then perform action. And it's syntax looks like this:

if(test-expression){statements-to-perform-when-true}

We could want the different action if that relationship is false. By appending else statement, it is possible.if-else statement looks like this:

if(test-expression){statements-to-perform-when-true} else{statements-to-perform-when-true}

Controlling with switch

[edit | edit source]

When we have multiple case to check, using if-else statement repeatedly is not efficient.In this case, switch is more useful.

Looping for

[edit | edit source]

Looping while

[edit | edit source]

Declaring & Defining Functions

[edit | edit source]