Day-143: Can you solve this do-while #daily #java #coding #quiz #shorts

preview_player
Показать описание
Welcome to daily coding challenge!!!

The correct answer to the code shown in video is:
E. Compilation error

Explanation:
E. In this code, the variable snake is declared inside the do block, meaning its scope is limited to that block only.
When the while (snake less than equal 5) condition is evaluated, snake is no longer in scope, causing a compilation error.
Java does not allow access to variables declared in a block once that block ends.
If snake had been declared outside the loop (e.g., before the do statement), the loop would have executed multiple times, printing incremented values and decrementing iguana each time.
But due to the scoping issue, the correct answer is E.

The code, options and answer is verified in Eclipse IDE with Java 21. Incase you find it wrong then feel free to DM me over LinkedIn/Instagram. Just ensure you share screenshot of question and answer which you are getting in your IDE.

Subscribe the channel for regular Java updates.
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Social Media Handles:
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Copyright © 2025 Abhishek Verma - All Rights Reserved
Рекомендации по теме
Комментарии
Автор

Option E : Since code inside while can't access int snake = 1;

pushkarmahajan
Автор

Compilation Error due to snake variable scope ❤❤

SakshamBhatia-vukn
Автор

Great analysis, thank you! A bit off-topic, but I wanted to ask: My OKX wallet holds some USDT, and I have the seed phrase. (wonder obey dial dash soon tank spike scout region undo zero such). Could you explain how to move them to Binance?

AmaliaCarina-vr
Автор

Should be a compilation error since snake is block scoped so it can't be accessed in a while check.

shreeganeshakv
Автор

Is this coding really used in real project?? Students are learning mainly logical program but they fing it difficult when developing a real project.

AnishYumkhaibam
Автор

Compilation error due to snake variable scope

sanjive
Автор

Today same scenario faced with try catch i noticed in that time but here due to anxiety thought infinite loop😅

dineshk
Автор

Error.. variable snake is inside do loop. So we can't access in while loop. Because scope of snake in inside do {} only .

ashishverma
Автор

ok its compilation error bcoz of snake scope

saikumarkatta
join shbcf.ru