Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

Правка en3, от jashinpunch, 2022-09-19 08:44:37

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)

Теги begginers

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский jashinpunch 2022-09-19 08:44:37 17
en2 Английский jashinpunch 2022-09-17 12:30:16 37 Tiny change: 'solving \n**112A — Petya and Strings** \n[112A &' -> 'solving \n[112A &'
en1 Английский jashinpunch 2022-09-17 12:29:43 1101 Initial revision (published)