What is the difference between if and else if in C? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 2

What is the difference between if and else if in C?

C programming

21st Jun 2020, 3:20 AM
Ravi Raj Rajput
Ravi Raj Rajput - avatar
2 ответов
+ 1
"if" is a keyword used to indicate a code block that will only be executed if a certain specified condition is met. "else" is another keyword that allows a code block to be executed if the condition specified on the "if" statement does not hold. C allows chaining multiple "if" statements by using the "else if" notation. In an "else if", the code block will be executed if the previous conditions didn't hold, but the current one does. if (a < b) printf("Less than\n"); else if (a > b) printf("Greater than\n"); else printf("Equal\n"); In other languages, the "else if" may be another different keyword: "elsif" (VHDL) or "elif" (Python).
21st Jun 2020, 3:25 AM
Felipe BF
+ 2
Thanks Felipe BF
21st Jun 2020, 3:27 AM
Ravi Raj Rajput
Ravi Raj Rajput - avatar