Please read the new rule regarding the restriction on the use of AI tools. ×

jashinpunch's blog

By jashinpunch, history, 2 years ago, In English

The difference between "if-else if" statement and multiple if statements

Today I learned that if-else if statement and multiple if statements are different. It might sound silly but up till now i thought they were the same thing.(I'm a beginner)

I was having trouble solving 112A — Petya and Strings (stuck on test 7 although I was quite sure that my logic was not wrong).

My last edit to the code was changing the if-else if statement to 2 if statements and it suddenly worked.

I was very surprised to see that and only then I finally noticed that they were different. While the if-else if statement only executes the latter if statement when the first if statement is false, multiple if statements are guaranteed to execute all of them.

112A taught me something new today and I hope some other complete beginner like me learns something from this blog too.(Probably everyone knows this I'm a idiot)

  • Vote: I like it
  • +7
  • Vote: I do not like it

| Write comment?