+ 1

Conditional Statement

Can a “if” statement be use without an “else” statement?

5th Nov 2022, 11:19 AM
Joseph Chukwudiegwu
Joseph Chukwudiegwu - avatar
5 odpowiedzi
+ 7
Yes in any language it is possible.
5th Nov 2022, 12:01 PM
A͢J
A͢J - avatar
+ 3
It depends on the language. For whichever language you are interested in, the easiest way to get an answer is to just try it. If the compiler or interpreter doesn't complain, it works.
5th Nov 2022, 11:29 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 2
Yes, if block statement use without else statement, and why use if-block statement mostly? because if the if-block condition false then it goes to else block statement, otherwise no problem if we use if-block statement without the else statement.
5th Nov 2022, 3:37 PM
Sakshi [Offline 🙃]
Sakshi [Offline 🙃] - avatar
+ 1
Yes, the if statement can be used without “else” because if only executes the indented block of code as long as the condition evaluates fo True, while else only execute if the “if” statement does not evaluate to “True”.
7th Nov 2022, 4:08 AM
Hunter
Hunter - avatar
- 1
Yes, if only the condition is “True”.
5th Nov 2022, 7:49 PM
Joseph Chukwudiegwu
Joseph Chukwudiegwu - avatar