Docsity

Fundamentals of Programming: Control Structures (if, else, elseif), Cheat Sheet of Programming Languages

Partial preview of the text

Download Fundamentals of Programming: Control Structures (if, else, elseif) and more Cheat Sheet Programming Languages in PDF only on Docsity!

Fundamentals of Programming

Lecture 4 b: Control Structure if else if elseif else

Agenda

  • if else C++ statement
  • Nested if else C++ statement
  • if elseif else C++ statement

Relational Operators

Precedence of Operators

if Statement

  • “if statement” It is a program uses to compare the input data with a condition; to decide what to do if the input data matches the condition or not
  • “if” uses with first condition that evaluates to true
  • “else” come after “if” or “else if” it use without condition and it evaluates to false

if Syntax

Example

if…else Statement

  • If the condition is true − Program continues to next statement
  • If the condition is false − Program continues

if…else Statement

  • If the condition evaluates to true − The code inside the body of if is executed − The code inside the body of else is skipped from execution
  • If the condition evaluates to false − The code inside the body of else is executed − The code inside the body of if is skipped from execution

Example

if…else Statement Working

if…elseif…else Statement

Example