this question has answer here:
- ruby while syntax 2 answers
a while loop works or without do. please explain why following 2 snippets works same way.
without
doi = 1 while < 5 = + 1 endwith
doi = 1 while < 5 = + 1 end
the non-theoretical answer quite simply: because ruby syntax guide said so.
the language syntax guide defines do keyword optional both while , until loops.
from understand - , theory - allowing do optional rather required compatibility , allowing harmonic syntax within language.
i think of acknowledgment "gray" areas, things less absolute. same done in physics, light behaves both particle , wave , should acknowledge both aspects.
coming different languages , school of thought, while somewhere between pure keyword (like if) , method (like loop, defined under kernel module)
if statements not require do begin block of code , under same logic, while loops wouldn't require do keyword.
this while keyword.
on other hand, loop requires do keyword (or {block}), why shouldn't while have same semantics?
this while method (as far syntax goes).
ruby making programmer happy. allowing do optional makes programmers happy , doesn't require ruby programmer resign 1 school of thought related nature of while.
Comments
Post a Comment