Are if statements can only be used for numbers? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Are if statements can only be used for numbers?

I wanted to make a program that if I ask questions then can I use if statement

20th Nov 2020, 1:17 PM
Prasoon Sharma
Prasoon Sharma - avatar
6 Answers
+ 10
No, if stmts are not limited to comparing numbers Pls tag ur programming language..
20th Nov 2020, 1:21 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 5
If statements only accept boolean variable and expressions, not others. You need to perform comparison to generate a valid expression. i = 4 > 5 #false
20th Nov 2020, 2:51 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 1
Yes you can
20th Nov 2020, 1:22 PM
Andrei I
Andrei I - avatar
+ 1
No. You could use it also with string. Example: var test = "Hello"; if (test == "Hello") { print("Success"); }
20th Nov 2020, 1:34 PM
Giampio
Giampio - avatar
0
No. We could also use them for words. Example: if x == "Hello": print("Success")
20th Nov 2020, 1:20 PM
mnaeem08
mnaeem08 - avatar
0
https://code.sololearn.com/cyjh8S6LxnMm/?ref=app In this code, I used if statements involving not only numbers, but also words
20th Nov 2020, 1:21 PM
mnaeem08
mnaeem08 - avatar