FAQ Database Discussion Community


What is different between return 1 and return 0? And how backtracking work in given code?

c,function,boolean,return,backtracking
int solve(int a[]) { int index,i; index=find_index(a); if(index==101) { return 1; } if(index!=101) { for(i=1;i<=9;i++) { if(cheak_coll(a,i,index)==1 && cheak_grid(a,i,index)==1 && cheak_row(a,i,index)==1) { a[index]=i; if(solve(a)) { return 1; } a[index]=0; } } } else { return 1; } return 0; } In given example what is different between return 1 and...

Save a Jtable to a file I created with a boolean column

java,swing,jtable,boolean,bufferedwriter
I'm trying to save a jtable on exit but I can't because I have a boolean as one of my columns. Can anyone explain to me how to get rid of java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String? this is my code to save on Exit. private void btnBckMouseClicked(java.awt.event.MouseEvent evt)...

Assign true to a variable if it is in a list?

python,list,boolean
aBool = bool(aList.index(aVal)) I tried this but it gives an error for false. Any help is appreciated!...

Compare 2 arrays and list the differences - Swift

arrays,swift,boolean,compare
I was wondering how one would go about comparing 2 boolean arrays and listing the non matching booleans. I have written up a simple example of 2 arrays. let array1 = [true, false, true, false] let array2 = [true, true, true, true] How would I compare array1 & array2 and...

How to use optional unwrapping and a boolean condition in a single if condition

swift,boolean,optional
I want to check whether an object is type of NSNumber and a boolean variable is true or not in a single statement. For this I wrote as below: let someBool = ... if value.isKindOfClass(NSDictionary) { // do something with dict } else if (let number = value as? NSNumber)...

Change image.Source in ListView according to boolean

c#,wpf,xaml,listview,boolean
I have a listview with 2 columns: "visibility" and "name" of a system. The value of column 1: a button (btn_visibility) with an image (img_visibility). Depending on a boolean (true or false) from an object in code behind the image should change, e.g. SYSTEM.SHOW_IN_LIST = true; img_visibility.Source = new BitmapImage(new...

find stretches of Trues in numpy array

python,arrays,numpy,boolean
Is there a good way to find stretches of Trues in a numpy boolean array? If I have an array like: x = numpy.array([True,True,False,True,True,False,False]) Can I get an array of indices like: starts = [0,3] ends = [1,4] or any other appropriate way to store this information. I know this...

What does this error mean? (errorC2678) and how do I fix my code?

c++,class,methods,vector,boolean
My bool method here is supposed to be checking for the character "-" within a multidimensional vector saved as private object "sudoku_". It returns true if it finds a "-" and returns false otherwise. It's really straightforward, so I don't know why I'm getting this error: "error C2678: binary '=='...

How is a string value used as a boolean

.net,vb.net,string,visual-studio,boolean
I was playing around with my code in VB.NET (Visual Studio IDE) when I realised that I could affect a boolean value into a string The string consequently took the value "True" or "False" I then tried using it as a boolean such as If StringValueContainingTrueOrFalse then 'Do Something End...

How to use relations between a Parse subclass and an User - Swift

swift,parse.com,boolean,relation
I am building a Quiz App and I have a class named "Questions" in Parse. When my user answers a question, I wanted that question to be removed from the questions that he needs to answer. I then wanted to add a subclass named "QuestionAnswered", a boolean that would return...

Java store boolean array in file and read fast

java,arrays,io,boolean
I need to store boolean array with 80,000 items in file. I don't care how much time saving takes, I'm interested only in the loading time of array. I did't try to store it by DataOutputStream because it requires access for each value. I tried to make this by 3...

Java boolean value is always true

java,constructor,boolean
I'm having trouble with my school Java code - I'm trying to create a constructor that takes a boolean value, and then uses it later, but for some reason it's always true. Could anyone tell me what I'm doing wrong? EDIT: I'm posting my entire code, I thought redacting it...

In javascript is there really a good reason to never check for boolean true || false such as if(var){}else{}?

javascript,boolean,typeof
I am fairly certain this isn't a duplicate so please bear with me. I check for boolean true||false using if() as a matter of course in my programming. I've programmed extensively in PHP, some in C# ASP.NET, a bit in Java, a long time ago in C++, & dabled in...

Passing boolean parameters in Ruby on Rails

ruby-on-rails,ruby,curl,boolean
My Ruby on Rails function should receive a boolean parameter, check it and, if it is true, do something. def isReady if (params[:ready] == true) doSomething() end end However, with the example below we never get inside this if (but it enters the function), probably because the parameter is passed...

Using the boolean value from appdelgate all across app

ios,boolean,appdelegate
In my app I need to check whether a user already exists or not and need to update accordingly. In order to achieve this I have created a boolean in appdelegate.h and accessed it all across the app. I need to do @property(strong,nonatomic)AppDelegate*appDelegate; appDelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate] in view did...

Java boolean and null strangeness

java,boolean
Could anyone please helpe me in understanding why my code could generate the following output? Please note, that f is here for debug purpose, f[0]=(lastLine!=null) is just an equivalent to lastLine!=null test, so it is not the bug. boolean f[] = new boolean[6]; if (f[0]=(lastLine!=null) // есть следующая строка ||...

Date Struct is not properly being checked

c++,struct,while-loop,boolean
I have some C++ code: #include <bjarne/std_lib_facilities.h> struct Date { int month; int day; int year; }; Date get_date(); Date get_birth_date(); int days_in_month (int month); bool is_valid_date (const Date& date); bool is_before (const Date& date1, const Date& date2); int main() { cout << "Welcome to Age Calculator!\n"; Date current; current...

My object is being destructed right after being constructed

c++,arrays,constructor,boolean,destructor
I'm trying to construct a two-dimensional boolean array with a class I've created called Grid. The Grid object is a private member class of another class called GameOfLife. Whenever I create a GameOfLife object with the parameters belove, the Grid object first gets created with the default constructor, then it...

Why is ((ans != 'N') || (ans != 'Y')) always true?

java,while-loop,boolean
I'm trying to prompt the user to spin again and my "while" expression is always coming back as false... Anyone have any ideas? reSpin = false; if (reSpin == false){ System.out.println("Would you like to spin again? Y/N"); char ans = in.next().charAt(0); if (ans == 'Y'){ reSpin =true; }else if (ans...

How to call a Boolean method from another method?

ios,boolean,void
I am creating a iOS App. I have created a method, in this method I want to call another method that should return BOOL value. Based on the return value I need to perform an operation. I am beginner in iOS. Any help related to this is much apppreciated.

Trying to set hidden input's value to toggle between True and False in JavaScript

javascript,html,boolean
I am attempting to toggle the value of hidden inputs between true and false by users clicking on table cells. I am able to successfully assign event handlers to the cells, and get their values. My toggling function (true_switch) appears to always return false, however, and I can't be sure...

LabView: Boolean Array to Number Block TroubleShooting

arrays,boolean,labview
I am using an EV3 Cube to scan a sheet that represents a binary number; i.e a black line represents a 1 and a white line represents a 0. Using this, I generate a numeric array consisting of 1's and 0's and convert them by using an Index Array to...

how to convert bool array to char variable

c#,char,boolean,type-conversion
I have a boolean array which holds some values that represent ASCII value: bool[] myBoolReceived = new bool[8]; I try to convert it to a char so I can add it to a list that holds chars. myReceivedMessage = new List<char>(); I tried to use Convert.ToChar method but it not...

Why does this code in java print a reference instead the result of invoking the method?

java,arrays,methods,reference,boolean
I am supposed to write a method that accepts 3 2-D arrays of This method should determine whether one of the matrices is the result of matrix addition of the other two. public class Matrix { public static void main(String[]args){ int [][] a = {{5,2,3},{4,1,6},{0,7,2}}; int [][] b = {{1,2,3},{4,5,6},{0,1,2}};...

Condensing code: Check that multiple columns follow a boolean in data frame in R

r,boolean,data.frame
I have a data frame (df) that has some NA values. I wanted to extract the rows where there are NA values across multiple columns (in the example below, I am doing so for columns 12-20): NArows = which(is.na(df[,20])&is.na(df[,19]&is.na(df[,18])&is.na(df[,17])&is.na(df[,16])&is.na(df[,15])&is.na(df[,14])&is.na(df[,13])&is.na(df[,12]))) Is there a more readable (and condensed) way to accomplish this,...

Get a Matrix from another Matrix

java,arrays,matrix,boolean
So guys, I'm developping a program for Structural Analysis and I came across a problem that I'm having some problem to solve. Basically, I have a system of equations, of which I only need to solve some of them. The ones I need to solve depend on a boolean array,...

How do I undo True = False in python interactive mode? [duplicate]

python,boolean,python-2.x
This question already has an answer here: python naming conflict with built-in function 7 answers So I tried the "evil" thing Ned Deily mentioned in his answer here. Now I have that the type True is now always False. How would I reverse this within the interactive window? Thing...

Matrix with boolean values from a list of paired observations

excel,matrix,boolean
In the below spreadsheet, the cell values represent an ID for a person. The person in column A likes the person in column B, but it may not be mutual. So, in the first row with data, person 1 likes 2. In the second row with data person 1 likes...

Evaluate multiple boolean conditions exclusively, only one can be true (Delphi)

delphi,boolean,operand
I have a function which is evaluate multiple (7, in my case) boolean variables and conditions and the result is true if only one of them true (and the rest false of course). I have the following code: function GetExclusiveTrue: boolean; begin Result:= ( Integer(BoolVar1) + Integer(BoolVar2) + Integer(BoolFunc3) +...

Visual basic 2008 - Do…While until infinite loop when shuffling 52 card deck

vb.net,visual-studio-2008,boolean,infinite-loop,do-while
I'm starting to make a Hearts game in VB2008. Currently I'm stuck with the dealing: For q = 0 To 51 Do Randomize() dealrand = Int(Rnd() * 51) cards(q).Image = pics(dealrand) Loop Until dealused(dealrand) = False dealused(dealrand) = True Next What I'm trying to do is check if the card...

Scala: “explicit return” required?

java,scala,boolean,return
I thought in Scala I don't need to explicit put "return" in the return statement. So I have the following code: def checkSimple(str1: String, str2: String): Boolean = { if (str1 > str2) { println("str1 > str2") true } println("str1 <= str2") false } if I ran my above code...

Checking strings

arrays,ruby,string,boolean
The function is supposed to return true only if all letters have "+" on both sides, but I always get true as my value... What's the flaw in my code? def SimpleSymbol?(str) str_array = str.split("") i = 0 while i < str_array.length-1 if ((str_array[i] >= "a") && (str_array[i] <= "Z"))...

How do i search an array in php and return true if it finds one of my variable?

php,arrays,search,boolean,return
if (array_search($soca, $user_socs)) I know that this will search the array by inputing a variable and an array but i was wondering if it is possible to make it return true, because since it doesn't return true, my if statement is not being carried out. References array_search documentation ...

Need to use BOOL* instead of BOOL

objective-c,c,xcode,pointers,boolean
I am making a chess game in Objective-C. In this game I need to use BOOL* instead of BOOL because I need a pointer to a boolean variable. When I try to use BOOL*, it gives me a warning when I try to do this: BOOL *isWhiteTurn; isWhiteTurn = YES;...

Finding the last occurrence of text in a column to result in adjacent cell value

excel,if-statement,boolean,conditional-operator
This is the current formula that works well when copied down, but now I want the false value to no longer be "", and instead be the value that is 2 columns adjacent to it. =IF(OR(F2="Craps",F2="$$$",F2="PtEst"),"ComeOut","") For instance, when this formula is in cell G3, I want it to return...

ifstream variable not reading correct character 1

c++,boolean,ifstream
I have an issue with the following code snippet. I have a file referred to with the character array FileName. The file could be basically anything, but in my case it is a file the contains some irrelevant text on the first line and then some lines that start with...

Python: extract values from list using an array with boolean expressions

python,arrays,list,boolean
I have a list of tuples like this: listOfTuples = [(0, 1), (0, 2), (3, 1)] and an array that could look like this: myArray = np.array([ -2 , 9 , 5]) Furthermore, I have an array with Boolean expressions which I created like this: dummyArray = np.array([0, 1, 0.6])...

java recursion test if arraylist are equal

java,recursion,arraylist,boolean,compare
I have some code that I would like to make more efficient by recursion. Trouble is I don't know where to start. The code compares two arraylists a and b to see if they are equal. Assume the sizes of both arrays are equal. The code is public boolean isEqual(A...

Validation within Get/Set Methods Java

java,oop,boolean,encapsulation
I have the following code that verifies user input using get/set methods.Only strings are acceptable.The while loop should continue to execute till the time the user enters the correct data type.However,my while loop continues to execute despite identifying incorrect data types.Suggestions? public class SetGet { public static void main(String[]args) {...

How to have localStorage value of true?

javascript,string,boolean,local-storage
I was wondering if its possible for localStorage to have a Boolean value instead of a string? Using JS only no JSON if its impossible or can be done in JS a different way please let me know thanks http://jsbin.com/qiratuloqa/1/ //How to set localStorage "test" to true? test = localStorage.getItem("test");...

Java, For Loop in Class

java,class,methods,constructor,boolean
I'm a novice programmer and I am creating this program where I would like to create a list of booleans of size ten and then set all the values to false. As I have understood in Java one is not supposed to place code directly in a class without surrounding...

How can I make a loop in swich case(swift)?

ios,xcode,swift,loops,boolean
I wrote that code but I cannot make a loop in false condition. How can I make a loop for false condition? Note: "isConnectedToNetwork()" returns a boolean expression. switch Reachability.isConnectedToNetwork() { case false : println("Internet connection FAILED") var alert = UIAlertView(title: "No Internet Connection", message: "Make sure your device is...

Strange unmarshalling behavior with union in C#

c#,boolean,unmarshalling,unions
I want to export a C-like union into a byte array, like this : [StructLayout(LayoutKind.Explicit)] struct my_struct { [FieldOffset(0)] public UInt32 my_uint; [FieldOffset(0)] public bool other_field; } public static void Main() { var test = new my_struct { my_uint = 0xDEADBEEF }; byte[] data = new byte[Marshal.SizeOf(test)]; IntPtr buffer =...

NullPointerException throws when I use ternary operator [duplicate]

java,boolean,ternary-operator,boxing,unboxing
This question already has an answer here: NullPointerException through auto-boxing-behavior of Java ternary operator 3 answers I have the following return statement: public Boolean foo(String booleanString){ return ("true".equals(booleanString) ? true : ("false".equals(booleanString) ? false : null)); } when booleanString equal not true and not false I get the NullPointerException....

Return True if all characters in a string are in another string

python,string,boolean
Alright so for this problem I am meant to be writing a function that returns True if a given string contains only characters from another given string. So if I input "bird" as the first string and "irbd" as the second, it would return True, but if I used "birds"...

Yes or No instead of True or False in Knockout

javascript,knockout.js,binding,boolean
In Knockout is there a clean way to display a boolean property from my view model to show 'Yes' or 'No' instead of True / False. Sometimes the property is undefined so this should also show No. Currently using : <td data-bind="text: isAvailable ? 'Yes' : 'No'"></td> Must be a...

AS3 - Error #1056: Cannot create property 0 on Boolean

arrays,actionscript-3,boolean
I'm in need of creating multiple dynamic arrays and seem to have found exactly what I need at https://jadendreamer.wordpress.com/2012/05/06/flash-as3-tutorial-how-to-create-2d-or-3d-dynamic-multi-dimensional-arrays/ Example 1: var multiDimensionalArray:Array = new Array(); var boolArray:Array; var MAX_ROWS = 5; var MAX_COLS = 5; //initalize the arrays for (var row = 0; row <= MAX_ROWS; row++) { boolArray...

Java boolean method return

java,netbeans,boolean
I have a boolean method in my Java program and I'm wondering why NetBeans is recommending making this change to my code: return isPrime != 0; What I wrote was: if (isPrime == 0) { return false; } else{ return true; } Both work correctly but I cannot understand the...

Getting bit-pattern of bool in Swift

swift,int,boolean,type-conversion,bit-manipulation
In ObjC, a bool's bit pattern could be retrieved by casting it to a UInt8. e.g. true => 0x01 false => 0x00 This bit pattern could then be used in further bit manipulation operations. Now I want to do the same in Swift. What I got working so far is...

I can't figure out where this NullReferenceException is coming from

c#,.net,linq,boolean
EDIT Upon further reflection I decided to amend my answer below to reduce the possibility of misinterpretation of the problem. I am getting a NullReferenceException on this IEnumarable LINQ query: designations.ForEach(desg => desg.ModifiedBy.UserName = userNames.SingleOrDefault(name => desg.ModifiedBy != null && name.Id == desg.ModifiedBy.Id) != null ? userNames.SingleOrDefault(name => name.Id ==...

Why is the common type of bool and int8_t an int32_t in C++?

c++,c++11,boolean,std
I'm curious about some of the behavior of the builtin bool type in C++. As I understand it, std::common_type determines the common type using implicit convertibility. I would expect that an expression with bool and another type would cause bool to convert to that type. For instance, I can see...

wpf RadioButton Binding to different properties

wpf,boolean
I have the following SQL table structure DeleteOwn as bit 0 or 1 DeleteAll as bit 0 or 1 NoDelete as Bit 0 or 1 In XAML I have the following <RadioButton IsChecked="{Binding CurrentItem.Item[DeleteOwn]}" Content="Delete Own" HorizontalAlignment="Left" Margin="21,46,0,0" VerticalAlignment="Top"/> <RadioButton IsChecked="{Binding CurrentItem.Item[DeleteAll]}" Content="Delete All" HorizontalAlignment="Left" Margin="21,67,0,0" VerticalAlignment="Top"/> <RadioButton IsChecked="{Binding CurrentItem.Item[NoDelete]}"...

Python: Eliminating rows in Pandas DataFrame based on boolean condition

python,pandas,boolean,dataframes
Suppose I have a DataFrame in Pandas like c1 c2 0 'ab' 1 1 'ac' 0 2 'bd' 0 3 'fa' 1 4 'de' 0 and I want it to show all rows such that c1 doesn't contain 'a'. My desired output would be: c1 c2 2 'bd' 0 4...

Boolean Understanding [closed]

java,boolean
I am trying to wrap my head around a problem I am having with a practice problem using boolean expressions. I want to create a program that says if someone should ride a bike or not. I have two variables and want to write an AND statement and an OR...

Range Loop for Data Clean-up

excel,excel-vba,for-loop,boolean,conditional-formatting
This seems like it should be simple, but I have been getting error codes all afternoon: I have data that I am trying to clean up to graph (it's exported from a retaining system that sometime leaves "blank" cells not actually blank). So, I figured I could run a "IsNumeric"...

What is the efficient way of boolean value assignment in java?

java,boolean,variable-assignment
We can assign boolean value in three ways boolean isDone; isDone = true; isDone = Boolean.valueOf(true); isDone = Boolean.TRUE; so which assignment is more efficient? ...

Why does (true && {}) evaluate to {}, but ({} && true) evaluates to true? [duplicate]

javascript,boolean,boolean-logic
This question already has an answer here: Behaviour of and operator in javascript 1 answer As the title said, I can't quite understand why (true && {}) gives me {}, but the reverse is not the same. Edit: As a followup, since I'm using a boolean operator, why does...

Replace checkbox with String for Booleans in DefaultTableCellRenderer

java,swing,jtable,boolean,tablecellrenderer
I've been trying to learn JTable renderers, and have nearly nailed down the behavior I'm looking for, save for this last part. I want to remove the checkbox that JTable renders by default for booleans and render a simple String instead, and I just can't wrap my head around my...

Displaying boolean values from database in the view with Rails

ruby-on-rails,boolean
So I've got this table on my database full of boolean values and I want to be able to display them in one of my views, but not as a simple "true" or "false" string, which is the default. I am new to Rails so I don't know what to...

Java JComboBox icon

java,swing,jtable,boolean,jcheckbox
Displaying data in a JTable. One column serves as a field Checkbox. The problem is that instead of the icon appears in the display ChceckBox true / false. How do I fix this? Add data: private DefaultTableModel headermodel = new DefaultTableModel(); private JScrollPane scrollHeader = new JScrollPane(); private JTable headerTable...

by boolean, how to change existing chars to be true

java,arrays,multidimensional-array,boolean
My code is like this public class AsciiGrid { private static int ascrow = 0; private static int asccol = 0; private static char[][] myAsciiGrid; private boolean [][] GridOccupied; private static char space = ' '; . . . . . public String toString() { String[][] mystring = new String...

Accessing boolean var as array in PHP return NULL

php,arrays,boolean
discussing with a friend of my work, we discover something weird about PHP. Let's get the following code: <?php $leo = false; $retorno = $leo[0]; var_dump($retorno); The return of var_dump() is NULL. Now, the thing is, why is returning NULL, if we are trying to access a bool as array?...

java - why does this code print the output it is supposed to print if a Boolean is true but the Boolean was declared to false?

java,boolean
I have the following code: import java.util.*; public class Test { public static void main(String[] args) { boolean b = false; if (b=true) System.out.println("one. b = false"); if (b) System.out.println("two. b = false"); } } The output is: one. b = false two. b = false I set b equal...

Ruby on rails if condition when adding new data to a sql table

sql,ruby-on-rails,boolean
I'm pretty new to ruby & ruby on rails and I have a little question : I want to set a boolean to true if the value of the entry is higher than X and another boolean to true if this value if lower than Y. I don't really know...

Boolean logic simplification

boolean,logic
I am trying to solve this but am having a hard time: ' means complement Y = A'B' + A'BC' + (A + C')' My attempt: A'B' + A'BC' + A'C A'(B' + BC' + C) Now this is where I am lost at. Somehow parenthesized expression evaluates to 1...

Using not to check if True [closed]

python,boolean
I've just done a very simplified version of the problem I'm trying to solve: test = [False] for element in test: if value not False: return True This is to check an element is True in a list. However, this returns a SyntaxError on line 3....

random between variables in C++?

c++,random,boolean
First of all, I am still a beginner at learning programming. So please pardon me! If i were to have 4 boolean values, let's say a[0] = true a[1] = false a[2] = false a[3] = true and I were to randomize ONLY true values, how am I suppose to...

Use bool array in if statement c++

c++,arrays,boolean
I'm a beginner to programming and Stackoverflow. I'm sorry for my bad formatting and my English. My question is if I can do the thing in the if brackets. Thank you :) for(int i=0;i<A.size();++i) { if(Alphabet[i]==false) cout<<A[i]; else if(Alphabet[i]==true) { cout<<endl<<A[i]; } } ...

Is there an object of type boolean in ios?

ios,objective-c,properties,boolean
I want to use a property that is nonatomic and weak but I can't use BOOL because it isn't an object. What is ios/objective-c's equivalent? Thanks. ...

Int cannot be converted to boolean?? converting code from C to Java

java,c,printing,int,boolean
I have a code that I am converting into Java, Im new to programming but I already have done some work on both PL, although I do not understand why I get this error The original C code is: #include <stdio.h> #include <conio.h> int main () { int i, j,...

Python selection limiter

python,select,filter,boolean,limit
I am working on a project where I must ask the user to make a selection, I must limit their answers between 1-4 and have the program inform them when they have made a unacceptable selection. My issue comes when I try to modify the limiter to not crash when...

How to perform boolean addition on an SQL select

sql,sql-server,select,sum,boolean
I have the following data in a database table column named timeSchedule 00100110 00010100 00110000 00110011 Boolean addition would result in 00110111 Is there a way to do this in sql? Something like select sumboolean(timeSchedule) from myTable Someone asked for DDL+DML.. here is an example: CREATE TABLE [dbo].[myTable]( [musPracticeID] [int]...

Java: Add all possible combinations of TRUE/FALSE to a list

java,loops,boolean,generator
I have seen other posts about this, but they are not exactly like this problem. I have this code: public static List<Boosters.Builder> GetBoosters() { List<Boosters.Builder> boosters = new ArrayList<Boosters.Builder>(); Boosters.Builder booster = new Boosters.Builder(); booster.setLarge(Bool.TRUE).setMedium(Bool.TRUE).setSmall(Bool.TRUE); boosters.add(booster); booster.setLarge(Bool.FALSE).setMedium(Bool.TRUE).setSmall(Bool.FALSE); boosters.add(booster);...

java micro-optimization: combine set of boolean instance variables to bit vector based on int

java,boolean,micro-optimization,bitvector
We have a classe with a high number of instances and run into memory problems. Therefore, we try to reduce the memory requirements of this class. One idea would be the following. The class has many boolean instance variables, each of which would take up one word in a naïve...

I cant get the CMD outputs to display in my textbox.

c#,cmd,textbox,user,boolean
Since Local User Group Management doesnt seem to be something I can query in C#, I figured I would do a down and dirty version of what I an trying to accomplish and I need some advice for best practices. THE GOAL: Essentially, I need to determine if the current...

Evaluation of 'not (False and True)'

python,python-3.x,boolean
I came across this example ("Hacking Secret Ciphers with Python", p135) and I'm confused: not (False and True) The example states that it evaluates to False, but I fail to see why. If the parentheses modify the precedence then surely we are evaluating: not (False) Which evaluates to True, doesn't...

While loop running incorrect number of times

java,random,while-loop,boolean
I am having trouble with a while-loop, as the if statement is meant to check if the button is empty if not repeat. However if the whole if statement is in a while-loop it reveals about 4 buttons after running the code for the first time. case HINT: Random random...

Rename true false boolean

python,sqlite,python-2.7,sqlite3,boolean
Was wondering if there is a way to change a boolean from true / false to in / out? My code below is a boolean switch but I want it to print in or out not 0 or 1 while True: Tag = raw_input("Please Scan your Tag: ") q =...

Embed words into array. Boolean issue.

c,arrays,boolean
Okay so ive been trying to make a Word Search game and need to embed words into a grid. The words cant overlap or go off the edges. Ive managed to generate a grid roughly like: .........X .........X .........X .........X .........X .........X xxxxxxxxxx Im trying to make is so that...

Simplify Boolean statements (Java)

java,boolean,expression
I am trying to simplify the following boolean expressions. However, I can't figure them out. I would like to know how to get to the answer. Where b is a boolean andnis anint` A. if (n==0) {b=true;} else {b=false;} // is it b=!n; ???? B. if (n==0) {b=false;} else {b=true;}...

C# bool statement throws strange exeption for seemingly unconnected double.parse(string)

c#,datetime,boolean
I'm an absolute begginer when it comes to C#. Trying to learn via examples. So I've found myself a nice little calculator tutorial. Everything goes fine up to last moment: code is working, but it doesn't take multidigit input like '33'. There's a bool statement there for turning arythemical operations...

Double compare in JavaScript looks weird [duplicate]

javascript,boolean,compare,boolean-expression
This question already has an answer here: chaining double equals == returns false 3 answers Let's var a = "first", b = "second", c = "first";. Expression a == c returns true, (of course!); a == c is true too. Then why does a == a == c return...

Why is `nil` discussed as boolean by treehouse?

ruby,boolean,computer-science
Why is nil considered a boolean or represented as a boolean value in the boolean tutorial for ruby? By definition, a boolean in computer science is a: data type, having two values (usually denoted true and false), intended to represent the truth values of logic and Boolean algebra. ...

Convert Switch state to Boolean

android-studio,boolean,toggleswitch
I'm trying to get the value of a switch (on/off) and tell the data to another class. I'm not using a switch statement, I have a physical switch which the user can check or uncheck. I need to get the value of this switch in order to use the data...

Java boolean returning true when declared false

java,boolean,bukkit
I am currently making a plugin from the 1.8 Bukkit API. This question however, has to do with booleans. From the beginning of my class file, I have this declaration of a boolean public static boolean lockchat = false; Then I have another boolean in the class file that is...

Why “if” is not doing anything in this boolean method?

java,methods,boolean
import java.util.Scanner;//import Scanner public class review{ //name of the program public static void main(String[]args){ // main statement Scanner i=new Scanner(System.in); System.out.println("Enter a string"); String b=i.nextLine(); System.out.println("Enter a letter"); char c=i.next().charAt(0); System.out.println("Answer is "+test1(b,c)); } public static boolean test1(String a, char b){ boolean result= true; for(int i=0;i<a.length();i++) if(a.charAt(i)==b) result =true; else...

Java breaking vs returning

java,switch-statement,boolean,break
I am using a boolean that returns true. When something like this happens: public boolean t(String label, String[] arguments) { boolean j = false; if (!j) { return true; } return true; } However, inside of this boolean I have a switch statement. As you may know, you break out...

Javascript onclick function with if and else not working the way its supposed to

javascript,html,if-statement,onclick,boolean
I'm trying to have a javascript function in my HTML page that shows more text whenever you click on a name, and then hides it if you click on the same name again or -eventually- shows different text when you click on another name. This is my HTML code: <section>...

Which is faster: (i == 0) or (i < 1)

actionscript-3,if-statement,actionscript,boolean
I recently heard that: //This: val1 * 0.5; //Is faster than this: val1 / 2; So I wonder if there is anything else like that, and so I ask: var val1:uint = 0; //Is This: if (val1 == 0) //faster than this?: if (val1 < 1) ...

Returning True if a sequence appears in a list

list,python-3.x,boolean,sequence
I need to write a function that takes a list of ints nums and returns True if the sequence 1, 2, 3, .. appears in the list somewhere. My approach: def list123(nums): num = "" for i in nums: num += i if "1,2,3" in num: return True else: return...

localStorage and boolean 'string'

javascript,html5,boolean,local-storage
Storing boolean value in localStorage, this value is converted to string. Now trying to converting back this value from localStorage to boolean, i need to use JSON.parse() method, the more handy !! doesn't work. Code sample: var test = false; localStorage['test'] = test; console.log("JSON.parse returns: ", JSON.parse(localStorage['test']), "expected: ", test);...

How to .count nested_attribute boolean?

ruby-on-rails,ruby,boolean,nested-attributes,sidebar
The nested attribute of quantifieds are results. In the results partial a User will checkoff if their quantified result is a :good thing or not. In the sidebar I want to .count how many good results the User has marked off to serve as a reference point of their success....

No extra Boolean cast in JavaScript

javascript,boolean,warnings,lint
In if statement's casting to a Boolean via double negation (!!) is unnecessary, because these if statements, for example, are equivalent: if (!!foo) { // ... } if (foo) { // ... } But what if casting to a Boolean via !! is in return statement? Like here: nameToSomething :...

Java check if a boolean is initialized

java,initialization,boolean
I'm not talking about checking if a boolean is null as a means to check if it is initialized. Because that won't work. So I thought this might work: public class MyClass{ private boolean setting; private boolean getSetting{ // get the setting; } public void main{ if (setting != (true...

Way to simplify this array insertion code?

c#,arrays,boolean,refactoring
If I have this code: array[0] = a < b ? c : d array[1] = a < b ? d : c Is there a way to simplify it elegantly? I know I can do something like this to avoid the double boolean check: if (a < b) {...

What is the difference between @YES/@NO and YES/NO?

objective-c,boolean,objective-c-literals
In Objective-c what is the difference between @YES/@NO and YES/NO? What types are used for each?

How to print BOOLs [duplicate]

objective-c,boolean
This question already has an answer here: How to print Boolean flag in NSLog? 8 answers I want to print a BOOL (which is documented to be a signed char) without any compiler warnings: NSLog(@"Parsing Result = %hhd", parsingResult); // inside some iOS program. Xocde 6 But I get...

Passing array to Boolean Function

c++,arrays,function,struct,boolean
I am working on a project for class and I have pretty much completed all my code I just have one issue (THE CODE IS IN C++). I'm not too great at using boolean functions especially in the case for this program. If you guys could help me write or...

Is there ever a reason to write .eqv. .true.?

boolean,fortran,fortran95
In logic, and in *ahem* properly designed programming languages, comparing a boolean to true is always redundant, i.e. a == True should be replaced by simply a. (And similarly, a == False by not a). Many languages, including C, don't have a proper boolean type so it can make a...

Why are non-const vector elements const?

c++,vector,boolean,const,extraction-operator
When I iterate over a vector<bool>, I find that the elements, dereferenced through the iterator, are recognized as if they were const. Why is that? Change either the container or the element type, such as list<bool> or vector<short>, and the elements are non-const. This code shows what I'm talking about:...