decision making statements in c

Posted under C++ Course On By mohammed.mutawe

Decision making statements in c

They are the exclusive clauses in programming languages, which are called conditionals because they contain a condition that is likely to be true or false. The uses of conditional clauses are many and varied within the code. They are the meeting point at which the programmer gives options to the machine.



Its use is widespread, and it is considered as a language of communication between the programmer and the computer, which brings satisfactory results while working in the program. To clarify its Syntax:

  • if (condition): begins with the word if, which means if in the Arabic language, and usually the condition contains a negation or proof of value. You can study the C++ operands lesson before continuing with this lesson.
  • {} braces: The braces here are different from those () and braces of this type {} are found in abundance in C++ and even in other languages.


Code for an empty conditional sentence:

if (x)




Do not forget that the conditional sentences if statement have many benefits that the programmer desperately needs during his work, and the most important benefits are:

  • Shortening the time: Instead of entering into useless iterative loops and consuming hardware resources, you may shorten all those calculations with one line of conditional sentences.
  • It accommodates a limited number of possibilities inside it, and it returns the value and closes the function immediately once the required condition is met.


Please, for a good understanding of the if statement, copy the following code into your code editor.

#include <string>
#include <iostream>

int main()
    using std::string;
    string str[8] = { "Welcome"  , "To" , "C++" , "Hello" , "World" , "Free" , "circle" , "online"};

    for (int i = 0; i < 8; i++)
        if (str[i] == "Hello")    //if statement
            std::cout << str[i] << " ";


    std::cout << "\n";

    return 0;


Leave a comment

Your email address will not be published. Required fields are marked *