Boolean क्या है
Boolean एक light switch है जो सिर्फ true या false हो सकता है। Programs इसका उपयोग हां-या-नहीं वाले सवालों के जवाब देने के लिए करते हैं।
In this page:
Syntax
val flag: Boolean = true
val result = value1 > value2
Boolean
एक Boolean या तो true या false रखता है और हर comparison और logical expression का result होता है। Booleans पूरे Scala में if statements और pattern match guards चलाते हैं।
कुछ languages के विपरीत, Scala कभी implicitly दूसरे types को Boolean में convert नहीं करता।
Note:
==, >, और < जैसे comparison operators हमेशा एक Boolean value में evaluate होते हैं।उदाहरण: Boolean
object Main extends App {
val isActive: Boolean = true
val isAdmin: Boolean = false
val isAdult = 20 >= 18
println(s"$isActive $isAdmin $isAdult")
}
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. #}
आम गलतियां
- किसी condition में
==के बजाय=का उपयोग करना, जैसेif (x = 5), जो compile नहीं होता। - capital letter के साथ
TrueयाFalseलिखना, जबकि Scalatrueऔरfalseउपयोग करता है। - किसी condition के रूप में
1या0जैसेIntका उपयोग करना, जबकि Scala numbers को booleans के रूप में नहीं मानता।
🔒
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: