Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the "if" statement considered a method?

Interesting discussion came up among my peers as to whether or not the "if" statement is considered a method? Although "if" is appended with the word statement it still behaves similar to a simple non-return value method.

For example:

if(myValue) //myValue is the parameter passed in {     //Execute } 

Likewise a method could perform the same operation:

public void MyMethod(myValue) {     switch(myValue)     {         case true:             //Logic             break;         case false:             //Logic             break;     } } 

Is it accurate to call (consider) the "if" statement a simple predefined method in a programming language?

like image 414
Edward Avatar asked Dec 29 '11 21:12

Edward


People also ask

Is a IF statement a method?

No, it's not considered a method as you may have already seen in the other answers.

Is an if statement a method Java?

The Java if statement is the most simple decision-making statement. It is used to decide whether a certain statement or block of statements will be executed or not i.e if a certain condition is true then a block of statement is executed otherwise not.

What kind of statement is the if statement?

An if statement is a programming conditional statement that, if proved true, performs a function or displays information. Below is a general example of an if statement, not specific to any particular programming language.

Is if a method in Python?

Python if statement is one of the most commonly used conditional statements in programming languages. It decides whether certain statements need to be executed or not. It checks for a given condition, if the condition is true, then the set of code present inside the ” if ” block will be executed otherwise not.


Video Answer


1 Answers

In languages such as C, C++, C#, Java, IF is a statement implemented as a reserved word, part of the core of the language. In programming languages of the LISP family (Scheme comes to mind) IF is an expression (meaning that it returns a value) and is implemented as a special form. On the other hand, in pure object-oriented languages such as Smalltalk, IF really is a method (more precisely: a message), typically implemented on the Boolean class or one of its subclasses.

Bottom line: the true nature of the conditional instruction IF depends on the programming language, and on the programming paradigm of that language.

like image 112
Óscar López Avatar answered Sep 22 '22 18:09

Óscar López