+ 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 Answers
+ 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