473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

variables not set

There seems to be problem with the following javascript code but I can't see
it.
tmpd = "September 14, 2007";
n = 0;
tf = false;
do {
n++;
tf = !(tf);
}
while (sdte[n]<>tmpd);
This script is in the header. The script includes two large arrays (200
elements).
The variables n, tf, and tmpd are used in javascript code in the body.
(Each is defined with a var statement at the beginning of the header script
script. If I comment out the do...while loop and insert "n=13;" (for
example), the code in the body works fine. I want tf to switch from true to
false with each pass through the loop. The looping will stop when tmpd
equals a date (in string form) in the sdte array.


Sep 9 '07 #1
6 1212
Bert wrote:
while (sdte[n]<>tmpd);
<should give a syntax error in JavaScript. I think you are looking
for !=
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 9 '07 #2
Bert wrote:
tmpd = "September 14, 2007";
n = 0;
tf = false;
do {
n++;
tf = !(tf);
}
You should use meaningful identifiers:

var sDate = "September 14, 2007";
while (sdte[n]<>tmpd);
As Martin wrote.
[...] I want tf to switch from true to false with each pass through the
loop.
You may omit the parantheses there, then.

Other ways for an alternating value would be

tf = -tf;

and

tf = n % 2;

Either one might be better suited to your yet unknown purpose.
The looping will stop when tmpd equals a date (in string form)
in the sdte array.
It would be less error-prone if you compared two Date objects.

It is not clear why you are doing this, but your approach
looks to me as if it there was a better one.
PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Sep 9 '07 #3
Thomas 'PointedEars' Lahn said the following on 9/9/2007 10:01 AM:
Bert wrote:
>tmpd = "September 14, 2007";
n = 0;
tf = false;
do {
n++;
tf = !(tf);
}

You should use meaningful identifiers:

var sDate = "September 14, 2007";
Whether an identifier is "meaningful" or not is up to the person writing
the code and the identifier tmpd may not be meaningful to you but that
doesn't mean it isn't meaningful to the OP.

You didn't mention the lack of "var" though.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 9 '07 #4
Randy Webb wrote:
You didn't mention the lack of "var" though.
You didn't read the OP thoroughly enough.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Sep 9 '07 #5
Thanks, this was what I needed!
Bert

"Martin Honnen" <ma*******@yahoo.dewrote in message
news:46**********************@newsspool2.arcor-online.net...
Bert wrote:
>while (sdte[n]<>tmpd);

<should give a syntax error in JavaScript. I think you are looking for
!=
--

Martin Honnen
http://JavaScript.FAQTs.com/

Sep 9 '07 #6
Bert wrote:
There seems to be problem with the following javascript code but I can't see
it.
tmpd = "September 14, 2007";
n = 0;
tf = false;
do {
n++;
tf = !(tf);
}
while (sdte[n]<>tmpd);
JSLint is very good at spotting errors like this.

http://www.JSLint.com/
Sep 10 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hal Vaughan | last post by:
First, I am aware of both SwingUtilities.invokeLater(), and of using Thread to create a new thread.  These are part of the problem. I want to have something running in the background, while the...
4
by: Torsten Bronger | last post by:
Hallöchen! I have a file that looks a little bit like a C header file with a long list of variables (actually constants) definitions, e.g. VI_ATTR_TIMO = 0x54378 .... Actually I need this...
1
by: mark4asp | last post by:
What are the best methods for using global constants and variables? I've noticed that many people put all global constants in a file and include that file on every page. This is the best way of...
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
7
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
7
by: misha | last post by:
Hello. I was wandering if someone could explain to me (or point to some manual) the process of mapping the addresses of host variables by DB2. Especially I would like to know when DB2 decides to...
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
4
by: icarus | last post by:
global_vars.py has the global variables set_var.py changes one of the values on the global variables (don't close it or terminate) get_var.py retrieves the recently value changed (triggered right...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.