← Back to Scala Course | Chapter 2: Variables & Types | Lesson 3 of 8

Boolean क्या है

Boolean एक light switch है जो सिर्फ true या false हो सकता है। Programs इसका उपयोग हां-या-नहीं वाले सवालों के जवाब देने के लिए करते हैं।

In this page:

  1. Boolean
Syntax
scala
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

markup
object Main extends App {
  val isActive: Boolean = true
  val isAdmin: Boolean = false
  val isAdult = 20 >= 18

  println(s"$isActive $isAdmin $isAdult")
}
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. #}
आम गलतियां
  1. किसी condition में == के बजाय = का उपयोग करना, जैसे if (x = 5), जो compile नहीं होता।
  2. capital letter के साथ True या False लिखना, जबकि Scala true और false उपयोग करता है।
  3. किसी condition के रूप में 1 या 0 जैसे Int का उपयोग करना, जबकि Scala numbers को booleans के रूप में नहीं मानता।
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.