course content

Course Content

Introduction to C++

if...elseif...else

The if...else construct branches your program and handles different "scenarios" of its outcome.

if...else consists of two parts: condition and consequences.

For example:

cpp

main.cpp

Here, we use the 2-lines comment.

There is also a handling of the "opposite" case using else:

cpp

main.cpp

There can be other if...else inside the if...else:

cpp

main.cpp

You can also use the else if construct:

cpp

main.cpp

question-icon

What will the program output?

Select the correct answer

Section 4.

Chapter 1