I've a simple if statement yet it executes even if condition is false.
What can be wrong?
var j = -1;
for (var i in files) {
var f = files[i].split('/', 1);
alert (j+','+i+','+(j == -1) || (folders[j] != f));
if ((j == -1) || (folders[j] != f)) {
alert (j+','+i);
j += 1;
folders[j] = f;
}
};
The second alert is shown even if the first shows condition = false.
O. Wyss 5 1103
On Apr 26, 8:00 pm, Otto Wyss <otw...@bluewin.chwrote:
I've a simple if statement yet it executes even if condition is false.
What can be wrong?
var j = -1;
for (var i in files) {
var f = files[i].split('/', 1);
alert (j+','+i+','+(j == -1) || (folders[j] != f));
if ((j == -1) || (folders[j] != f)) {
alert (j+','+i);
j += 1;
folders[j] = f;
}
};
The second alert is shown even if the first shows condition = false.
O. Wyss
how can j ever not be -1 in the code above, so the || condition is
always true, and when j is manually changed to say -2, the second
alert doesnt show.
On Apr 26, 11:53 pm, shimmyshack <matt.fa...@gmail.comwrote:
On Apr 26, 8:00 pm, Otto Wyss <otw...@bluewin.chwrote:
if ((j == -1) || (folders[j] != f)) {
alert (j+','+i);
j += 1;
folders[j] = f;
}
The second alert is shown even if the first shows condition = false.
O. Wyss
how can j ever not be -1 in the code above, so the || condition is
always true, and when j is manually changed to say -2, the second
alert doesnt show.- Hide quoted text -
j isn't alway -1 since after the first true condition j is set to 0 in
"j += 1". Besides the alert before really shows "false" for the full
condition.
O. Wyss
Figured out what was wrong, string compares works only with strings.
if ((j == -1) || (String(folders[j]) != String(f))) {
O. Wyss
wyo wrote:
Figured out what was wrong, string compares works only with strings.
if ((j == -1) || (String(folders[j]) != String(f))) {
O. Wyss
For the record, what were you parsing? My guess was arrays you
populated via server-side code.
--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
On Apr 26, 12:00 pm, Otto Wyss <otw...@bluewin.chwrote:
I've a simple if statement yet it executes even if condition is false.
What can be wrong?
var j = -1;
for (var i in files) {
var f = files[i].split('/', 1);
alert (j+','+i+','+(j == -1) || (folders[j] != f));
if ((j == -1) || (folders[j] != f)) {
alert (j+','+i);
j += 1;
folders[j] = f;
}
};
The second alert is shown even if the first shows condition = false.
You may wish to consider why the first alert:
alert (j+','+i+','+(j == -1) || (folders[j] != f));
gives a different result from:
alert (j+','+i+','+((j == -1) || (folders[j] != f)));
and decide which one would be the correct one to use.
--
../rh This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robert Brown |
last post by:
suppose I have the following table:
CREATE TABLE (int level, color varchar, length int, width int, height
int)
It has the following rows
1, "RED", 8, 10, 12
2, NULL, NULL, NULL, 20...
|
by: titan0111 |
last post by:
#include<iostream>
#include<iomanip>
#include<cstring>
#include<fstream>
using namespace std;
class snowfall
{
private:
int ft;
|
by: Matthew Wilson |
last post by:
I need to write a function crc(msg, len) that gets a char array of
length len and then calculates the crc32 for the code. I don't
understand what's going wrong in the code I have. It goes...
|
by: gt8887b |
last post by:
Hello!
In his recent newsletter embedded expert Jack Ganssle says that
programming students, as well as professional developers should readh
"great code" (hight quality/well-crafted code that...
|
by: Pyenos |
last post by:
import cPickle, shelve
could someone tell me what things are wrong with my code?
class progress:
PROGRESS_TABLE_ACTIONS=
DEFAULT_PROGRESS_DATA_FILE="progress_data"
PROGRESS_OUTCOMES=
|
by: robert maas, see http://tinyurl.com/uh3t |
last post by:
I'm working on examples of programming in several languages, all
(except PHP) running under CGI so that I can show both the source
files and the actually running of the examples online. The first...
|
by: amrhi |
last post by:
Whats wrong with my code , i cant access to next page.
Looks like the text field cant be read by login.php
Thanks
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
|
by: Stef Mientki |
last post by:
This might be a very weird construction,
but it's the most easy way in translating another language into Python (for simulation).
Although it works, I like to know if this a valid construction:
...
|
by: islayer |
last post by:
can someone tell me what is wrong with the bold code? i am just learning perl. the program should create a perl file with a random name (5 letters, followed by a number), but the name is always just...
|
by: Chedda |
last post by:
everytime i try to compile and run the program, on the compiler it states on line
where it says ofstream outfile("c:\\Users\\Michael\\Desktop\\Statistics.txt");#include <iostream> that theres an...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |