, ,



learn coding C++ programming language for hackers kali linux 2.0 k4linux

Learn C ++ Programming Language For Hackers [Lesson 2]

After the first Lesson about Learning C++ Programming Language For Hackers, today we will explain to you how to use IF statement on C++.

The ability to regulate the flow of your program, belongings it create selections on what code to execute, is efficacious to the programmer. The if statement permits you to regulate if a program enters a section of code or not supported whether or not a given condition is true or false. one among the vital functions of the if statement is that it permits the program to pick an action based mostly upon the user’s input. As an example, by using an IF statement to see a user entered password, your program will decide whether or not a user is allowed access to the program. While not a conditional statement like the if statement, programs would run nearly the precise same manner on every occasion. If statements enable the flow of the program to be modified, and then they permit algorithms and additional fascinating code.

Before discussing the particular structure of the if statement, allow us to examine the that means of TRUE and FALSE in computer word. A real statement is one that evaluates to a nonzero range. A false evaluates to zero. After you perform comparison with the relative operators, the operator can come 1 if the comparison is true, or 1 if the comparison is fake. As an example, the check 0 == 2 pair of evaluates to zero. The check a pair 2 == 2 pair of evaluates to a one. If this confuses you, attempt to use a cout statement to output the results of those varied comparisons (for example cout << ( 2 == 1 );)

When programming, the aim of the program can typically need the checking of 1 value keep by a variable against another worth to work out whether or not one is larger, smaller, or up to the opposite.
There area unit variety of operators that permit these checks.

Here square measure the relative operators, as they’re identified, along side examples:


>    greater than         5 > 4 is TRUE
<    less than          4 < 5 is TRUE
>=    greater than or equal         4 >= 4 is TRUE
<=    less than or equal         3 <= 4 is TRUE
==    equal to         5 == 5 is TRUE
!=    not equal to         5 != 4 is TRUE

It is extremely probable that you just have seen these before, in all probability with slightly totally different symbols. They ought to not gift any hindrance to understanding. Currently that you just perceive TRUE and FALSE in pc nomenclature similarly because the comparison operators, allow us to cross-check the particular structure of if statements.


coding c++ for hackers kali linux 2.0 k4linux

The structure of an if statement is as follows:


if ( TRUE )
Execute the next statement

To have quite one statement execute when Associate in Nursing if statement that evaluates to true, use braces, like we have a tendency to did with the body of a function. Something within braces is named a compound statement, or a block.

For example:


if ( TRUE ) {
Execute all statements inside the braces
There is additionally the else statement. The code once it (whether one line or code between brackets) is dead if the if statement is fake.
It can look like this:
if ( TRUE ) {
// Execute these statements if TRUE
else {
// Execute these statements if FALSE

One use for else is that if there area unit two conditional statements which will each value to true, however you want just one of the two to possess the code block following it to be executed. You’ll be able to use an else if once the if statement; that method, if the primary statement is true, the else if are going to be neglected, however if the if statement is false, it’ll then check the condition for the else if statement. If the if statement was true the else statement won’t be checked. it’s attainable to use various else if statements.

Let’s scrutinize an easy program for you to undertake out on your own.


using namespace std;
int main()                   // Most important part of the program!
int age;                   // Need a variable…
cout<<“Please input your age: “;     // Asks for age
cin>> age;                   // The input is put in age
cin.ignore();                   // Throw away enter
if ( age < 100 ) {                   // If the age is less than 100
cout<<“You are pretty young!n”; // Just to show you it works…
else if ( age == 100 ) {                 // I use else just to show an example
cout<<“You are oldn”;                   // Just to show you it works…
else {
cout<<“You are really oldn”;      // Executed if no other statement is

Boolean operators enable you to make a lot of advanced conditional statements. for instance, if you want to examine if a variable is each larger than 5 and fewer than 10, you may use the mathematician AND to make sure each both var > 5 and var < 10 are true. Within the following discussion of Boolean operators, i’ll capitalize the mathematician operators so as to differentiate them from traditional English. The particular C++ operators of equivalent perform are going to be represented additional into the tutorial – the C++ symbols are not: OR, AND, NOT, though they’re of equivalent perform.

Once using if statements, you may usually want to examine multiple totally different conditions. You must to perceive the boolean operators OR, NOT, and AND. The mathematician operators perform in a very similar way to the comparison operators: every returns 0 if evaluates to FALSE or 1 if it evaluates to TRUE.

NOT: The NOT operator accepts one input. If that input is TRUE, it returns FALSE, and if that input is false, it returns TRUE. for instance, NOT (1) evalutes to zero, and NOT (0) evaluates to one. NOT (any variety but zero) evaluates to 0. In C and C++ NOT is written as !. NOT is evaluated before each AND and OR.

AND: this can be another vital command. AND returns TRUE if each inputs aremeasure TRUE (if ‘this’ AND ‘that’ are true). (1) AND (0) would appraise to zero as a result of one among the inputs is false (both should be TRUE for it to guage to TRUE). (1) AND (1) evaluates to 1. (any variety however 0) AND (0) evaluates to 0. The AND operator is written && in C++. don’t be confused by thinking it checks equality between numbers: it doesn’t. confine mind that the AND operator is evaluated before the OR operator.

OR: terribly helpful is that the OR statement! If either (or both) of the 2 values it checks are TRUE then it returns TRUE. As an example, (1) OR (0) evaluates to 1. (0) OR (0) evaluates to 0. The OR is written as || in C++. Those are the pipe characters. On your keyboard, they’ll appear as if a stretched colon. On my computer the pipe shares its key with . confine mind that OR are going to be evaluated after AND.

learn c++ programming language for hackers kali linux 2.0 k4linux

It’s attainable to mix many boolean operators in an exceedingly single statement; typically you’ll realize doing therefore to be of nice price once making advanced expressions for if statements. what’s !(1 && 0)? after all, it might be TRUE. It’s true is as a result of 1 && 0 evaluates to zero and !0 evaluates to TRUE (ie, 1).

Attempt a number of these – they are not too hard.

A. !( 1 || 0 )         ANSWER: 0
B. !( 1 || 1 && 0 )      ANSWER: 0 (AND is evaluated
before OR)
C. !( ( 1 || 0 ) && 0 )    ANSWER: 1 (Parenthesis are

So that was ales with If statements in C++ in the next article we will talk about how to use Loops on C++ to Learn Programming Language as a Hacker!

If you have encountered a problem or you have any questions or remarks please feel free to set a comment.

If this article helped you to solve your problem please feel free to Share it with your friends. with Love and Prosperity K4LINUX-TEAM.

What do you think?

1 point
Upvote Downvote

Total votes: 1

Upvotes: 1

Upvotes percentage: 100.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

2 Pings & Trackbacks

  1. Pingback:

  2. Pingback:

Leave a Reply

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