comparison if statement in C, Matlab and Python programming languages | applied electronics engineering

Latest

comparison if statement in C, Matlab and Python programming languages

By Applied Electronics - Wednesday, March 8, 2017 No Comments
If statement is the basic branching statement in most of the programming language. In this tutorial we want to compare the if statement in Matlab programming language, python programming language and in the C programming language.

Let's start with C programming language because this is the oldest among them.

In C programming language the if statement is,


The condition after the keyword if is always enclosed within a pair of parentheses. If the condition, whatever it is, is true, then the statement is executed. If the condition is not true then the statement is not executed; instead the program skips past it.

The condition is evaluated using C’s relational operators. The relational operators compare two values to see whether they are equal to each other, unequal, or whether one is greater than the other.


An example of if statement in C programming language is shown below,



In matlab programming language the if statement is realized as follows,


An example of using if statement in Matlab is as follows,



Lastly let see the if statement in python programming language. In python the if statement syntax is as follows,



In particular, the first line starts with the if keyword, followed by a Boolean expression, and then a colon (:). Following the if line, a block of indented statements are written from the second line onwards. Here indentation refers to the insertion of whitespace characters, including spaces (‘’) and tabs (‘ ’) before a statement. Common indentations include 2–8 spaces and 1–2 tabs, while spaces are preferred because different text editors can interpret a tab character as different numbers of
spaces. A statement block contains one or multiple statements with equal indentation.

An example of if statement in python programming language is as follows.


Tags:

No Comment to " comparison if statement in C, Matlab and Python programming languages "