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

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

Revision en1, by jashinpunch, 2022-09-17 12:29:43

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 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 to 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 had some differences. 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)

Tags begginers

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English jashinpunch 2022-09-19 08:44:37 17
en2 English jashinpunch 2022-09-17 12:30:16 37 Tiny change: 'solving \n**112A — Petya and Strings** \n[112A &' -> 'solving \n[112A &'
en1 English jashinpunch 2022-09-17 12:29:43 1101 Initial revision (published)