Saturday, December 2, 2017

Conditional statements in C++ and Python (part 2)

if else conditional statement

In the if else conditional statement, one set of statement(s) is executed if the condition is true, otherwise, the other set of statement(s) is executed.


C++ Python
Syntax

if (condition)
{
        statement1;
        statement2;
                ...
}
else
{
        statement1;
        statement2;
                ...
}
Syntax

if condition:
        statement1;
        statement2;
                ... 
else:
        statement1;
        statement2;
                ... 





Example

int a = 10;
int b = 15;

if (a<b)
{
      cout<<"a < b.";
}
else
{
      cout<<"a >= b.";
}
Example

a,b = 10, 15;

if a<b:
     print("a < b") 
else:
     print("a >= b") 







No comments:

Post a Comment

Iterative statements in C++ and Python (Part 2)

for loop iterative statements Executing set of statements using for iterative statement in C++ and Python is quite different. First, l...