while और until
while तब तक repeat होता है जब तक एक condition true हो, और until तब तक repeat होता है जब तक यह false हो। यह soup hot होने तक stir करने बनाम इसके अभी भी cold होने तक stir करने जैसा है।
In this page:
Syntax
while condition
# body
end
until condition
# body
end
while और until
while condition इसका block तब तक repeat करता है जब तक condition truthy हो, हर iteration से पहले check होते हुए। until condition इसका inverse है, तब तक repeat करते हुए जब तक condition falsy हो।
दोनों एक single statement के लिए एक trailing modifier form भी support करते हैं, जैसे i += 1 while i < 10।
Note:
stopping point की तरह phrased conditions के लिए
until अक्सर while !condition से ज़्यादा naturally पढ़ा जाता है।उदाहरण: while and until
count = 1
while count <= 3
puts "While count: #{count}"
count += 1
end
count = 1
until count > 3
puts "Until count: #{count}"
count += 1
end
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- counter update करना भूल जाना, इसलिए
while count <= 3हमेशा के लिए चलता है। untilकोwhileसे confuse करना, जबuntilcondition false होने तक चलता है।- जब
eachयाtimessimpler हो और हमेशा के लिए loop नहीं कर सकता तबwhileइस्तेमाल करना।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: