Operator '==' cant be applied to 'Boolean' and 'Char'

operator math
operator c++
operator javascript
operator in c
operator python
operator biology
operator song

So i want to compare three members of an array with as little code as possible. Heres what i did:

for(i in 0..2) {
    if(board[i][0] == board[i][1] == board[i][2]) {
        return true
    } else if(board[0][i] == board[1][i] == board[2][i]) {
        return true

(All of the values ar Char's FYI) But it didnt work. I get this error message "Operator '==' cant be applied to 'Boolean' and 'Char'". I also tried using .equals, but that just didnt work. Any ideas on what to do?

You can write a small function to keep it more readable and tidy, especially if You need to do that comparison often:

fun allEqual(vararg items: Any) : Boolean {
    for(i in 1..(items.size-1)){
        if(items[0] != items[i]) return false
    return true

And invoke simply by comma separating values:

allEqual(board[i][0], board[i][1], board[i][2])

Operator, JavaScript Arithmetic Operators. Arithmetic operators are used to perform arithmetic on numbers: Operator, Description. +, Addition. -, Subtraction. a person who operates a telephone switchboard, especially for a telephone company. a person who manages a working or industrial establishment, enterprise, or system: the operators of a mine. a person who trades in securities, especially speculatively or on a large scale. a person who performs a surgical operation; a surgeon.

I don't know Kotlin specifically, but most* languages don't allow you to compare 3 values at the same time. What your error message is communicating is that your code ends up comparing

"Is board[i][0] equal to board[i][1]?" which is true/false (Boolean)


board[i][2], which is a Char.

*I don't know of any, but maybe there's one out there that does.

Operators in C and C++, Operators are used to perform operations on variables and values. In the example below, we use the + operator to add together two values: Example. int  Define operator. operator synonyms, operator pronunciation, operator translation, English dictionary definition of operator. n. 1. a. One who operates a machine or

You have included this condition:

if(board[i][0] == board[i][1] == board[i][2])

Firstly, this one is compared: board[i][1] == board[i][2]

After comparing, it returns true. After that if logic converts to:

if(board[i][0] == true)

Now, board[i][0] is a char and you are trying to compare it to a boolean which is not possible. That's why you are getting this error.

You have to change the logic to:

if((board[i][0] == board[i][1]) && (board[i][1] == board[i][2]))

So, your code will be:

for(i in 0..2) {
    if((board[i][0] == board[i][1]) && (board[i][1] == board[i][2])) {
        return true
    } else if((board[0][i] == board[1][i]) && (board[1][i] == board[2][i])) {
        return true

What is operator?, This section describes the operators and contains information about operator precedence. Assignment operators; Comparison operators  Jim Croce - Operator Lyrics. Operator, oh could you help me place this call. You see the number on the matchbook is old and faded. She's livin' in l.a. With my best old ex-friend ray. A guy she

Another approach:

for (i in 0..2) {
    if (board[i].toSet().size == 1)
        return true
    else if (board.map { it[i] }.toSet().size == 1)
        return true

what are operators ?what is its function​, Logical NOT operator. Arithmetic operators. Arithmetic operators take numerical values (either literals or variables) as their operands and return a  The conditional operator ?:, also known as the ternary conditional operator, evaluates a Boolean expression and returns the result of one of the two expressions, depending on whether the Boolean expression evaluates to true or false. Beginning with C# 7.2, the conditional ref expression returns the reference to the result of one of the two

As the others said, your first comparison returns Boolean, and the second compares Boolean to Char.

You can use an extension function, and transitivity to simplify things:

fun Any.equalsAll(vararg others: Any):Boolean
    others.forEach {
            return false
    return true

and call:

 if (board[0][i].equalsAll(board[1][i], board[2][i]))

C# operators, Hello, guys. Thanks for all the views!!!! I'd like to apologize for the advertisements that are being Duration: 3:50 Posted: Feb 21, 2010 The + and += operators are supported by the built-in integral and floating-point numeric types, the string type, and delegate types. For information about the arithmetic + operator, see the Unary plus and minus operators and Addition operator + sections of the Arithmetic operators article. When one or both operands are of type string, the

JavaScript Operators, All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left. Operator Precedence  => operator (C# reference) 01/22/2019; 2 minutes to read +6; In this article. The => token is supported in two forms: as the lambda operator and as a separator of a member name and the member implementation in an expression body definition.

C++ Operators, The null-coalescing operator ?? returns the value of its left-hand operand if it isn't null; otherwise, it evaluates the right-hand operand and returns its result. The ?? operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-null. Available in C# 8.0 and later, the null-coalescing assignment operator

Expressions and operators - JavaScript, >> (right shift) Takes two numbers, right shifts the bits of the first operand, the second operand decides the number of places to shift.Similarly right shifting (x>>y) is equivalent to dividing x with 2^y. /* C++ Program to demonstrate use of right. shift operator */ #include<stdio.h> using namespace std; // a = 5 (00000101), b = 9 (00001001)

  • Good and clean solution.
  • Python, according to docs.python.org/3/reference/expressions.html#comparisons
  • I'm only seeing binary comparisons in that reference
  • "Formally, if a, b, c, …, y, z are expressions and op1, op2, …, opN are comparison operators, then a op1 b op2 c ... y opN z is equivalent to a op1 b and b op2 c and ... y opN z, except that each expression is evaluated at most once." And == is listed as a comparison operator.
  • Just wanted to note that "firstly, this one is compared..." is not exactly accurate, as this would be a compile time error. So the compiler would infer that the first comparison would yield a Boolean type value, which it then sees to be compared to a Char, hence the error. Your solution is correct though.
  • @jingx I think you misunderstand me. I have explained that at the time of compiling it will execute in that way.
  • At compile time there is no such thing as "after comparing, it returns true".
  • Very late but you once again misunderstood Avijit's statement. They mention nothing about the compiler compiling the statement to a true. They are talking about "order". The compiler will generate bytecode, and this bytecode will first compare the last two equality operators and then compare the first against the result. The "if(board[i][0] == true)" Is not actually representing code it was purely for the sake of explaining the logic. The last two are computed first, then that result is compared against the first, at run time. They simply represented it as code for ease of understanding...