repeat का उपयोग
repeat तब तक हमेशा के लिए चलता रहता है जब तक आप इसे रुकने के लिए न कहें, एक merry-go-round की तरह जो तब तक चलता है जब तक कोई brake न खींचे। Brake एक break command है।
In this page:
Syntax
repeat {
# body
if (condition) break
}
repeat
repeat इसकी body बिना किसी built-in condition के indefinitely चलाता है, रुकने के लिए पूरी तरह अंदर एक break statement पर depend करते हुए।
यह दूसरी languages में मिलने वाले unconditional infinite loop का R equivalent है (जैसे C-family languages में while (true))। यह सबसे useful तब है जब exit condition शुरुआत में नहीं बल्कि loop body के बीच में check हो।
Note:
जब आपको loop body के बीच कहीं exit condition check करना हो, सिर्फ top पर नहीं, repeat सही choice है।
उदाहरण: repeat
count <- 1
repeat {
cat("Count:", count, "\n")
count <- count + 1
if (count > 3) {
break
}
}
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. #}
आम गलतियां
breakomit करना, इसलिएrepeatहमेशा के लिए चलता है।- counter update को
if (... ) breakके बाद रखना, इसलिए loop एक iteration बहुत देर से रुकता है। repeatइस्तेमाल करना जब एक clear condition वालाwhileपढ़ना आसान होता।
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: