Блог пользователя jashinpunch

Автор jashinpunch, история, 2 года назад, По-английски

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)

Полный текст и комментарии »

  • Проголосовать: нравится
  • +7
  • Проголосовать: не нравится