+ 1

If (-1) {}

What happens if the value of my if-statement becomes -1 ? Is it the same for all languages?

25th Oct 2018, 2:44 PM
Innocent Culprit
Innocent Culprit - avatar
3 Antworten
+ 1
Okay, that should be fine. More generally, any nonzero integer is treated as true.
25th Oct 2018, 3:35 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
For all the languages I know of, -1 is considered as true. So the if block will be executed.
25th Oct 2018, 2:57 PM
Kishalaya Saha
Kishalaya Saha - avatar
0
good to know, I wanted to reuse a function that returned -1 in the case of an error 😅
25th Oct 2018, 3:15 PM
Innocent Culprit
Innocent Culprit - avatar