Increment और Decrement
Increment and decrement एक counter को एक-एक बार click up या down करने जैसा है जब कोई आता है। आप बड़े steps में भी jump कर सकते हैं, जैसे एक साथ पांच जोड़ना।
In this page:
Syntax
((variable++))
((variable--))
((variable += value))
Increment and Decrement
Bash increment/decrement के लिए ((x++)) और ((x--)) support करता है, साथ ही ((x += 5)) जैसी compound assignment। ये सिर्फ (( )) जैसे arithmetic contexts के अंदर काम करते हैं, plain commands के रूप में नहीं। ये एक loop में counter update करने का concise तरीका हैं।
Note:
((x++)) x की *original* value के आधार पर exit status return करता है — अगर x 0 था, तो expression खुद set -e purposes के लिए "false" evaluate होता है।उदाहरण: Increment and Decrement
#!/bin/bash
count=0
((count++))
((count++))
((count += 5))
echo "Count: $count"
((count--))
echo "After decrement: $count"
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. #}
आम गलतियां
i++को एक command के रूप में अकेला उपयोग करना, जो valid नहीं है;((i++))याi=$((i+1))उपयोग करें।- यह न जानना कि
((i++))value 0 होने पर exit status 1 return करता है, जोset -eके under fail होता है। - Spaces के साथ
i = i + 1लिखना, जो एक assignment नहीं है।
🔒
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first: