lundi 20 août 2018

How does if work in programming? [duplicate]

This question already has an answer here:

From the past year of programming experience in php and js I have come to know that if statement work, if the conditions given to it is true. And does not work if the condition given is false.

eg:

`if(true){
 //runs
 }`

But now I wonder I don't really know how it works. As I have noticed the if clause runs if the value is not false.

eg:

`if(3){
  //Code runs when the condition is neither true nor false
 }`

Also it works the same in javascript and php. Suppose I supply array inside if statement then it runs whether it is true or not. But the same does not run if you don't have value inside array statement. Then isn't it false to assume that the if statement work when the condition is true? The answer seems to be if clause runs when the condition is not false.

Can anybody explain what is happening? And how are they setup in these programming languages(php and js)?

Aucun commentaire:

Enregistrer un commentaire