/    Sign up×
Community /Pin to ProfileBookmark

Programming Question

This question is a request for information that I want to use in a javascript,
but I don’t know where to look. I am asking for any information from more
experienced (or students of) programming languages.

I would like to know how to decipher the “if..then..else” logic of javascript.
I know how to use the language to do this, but I don’t understand the underlying
tokenization of the individual lines

Does anyone know of a source (book or website) that describes how to split strings into
logical segments that could be interpreted into actions.

For example, if I have the following pseudo command, how would I do the following?

if (some_condition_evaluated_to_true_or_false) { i=i+1 } else {i=i+10}

I would like to understand how this could be accomplished with ‘nested’ conditions as well.

I know this is not a direct javascript question, but I plan on using javascript
to split the strings into tokens or logic segments that would be executed by JS.

I have googled combinations of the following words, but don’t see much that helps me at this time: ‘program language logic commands tokens’
Any ideas are welcome, even if they don’t work.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@toicontienOct 21.2006 — JavaScript if-elseif-else constructs work the same as any other language.
[code=html]
<script type="text/javascript">
function testIFs(condition) {
if (condition == '1') {
alert('Condition 1');
} else if (condition == '1') {
alert('Condition 2');
} else {
alert('Default condition');
}
}

testIFs('1');
testIFs('2');
testIFs('3');
testIFs('3;4lywbsdfml');
</script>
[/code]

The code above illustrates the basics. You can nest if statements inside each other.

[code=html]
<script type="text/javascript">
function testIFs(condition) {
if (condition === '1') {
alert('Condition 1');
} else if (condition === '1') {
alert('Condition 2');
} else {
if (condition === 'easter egg') {
alert('You guessed the hidden default valuenof the first if statement!');
} else {
alert('Default condition');
}
}
}

testIFs('1');
testIFs('2');
testIFs('3');
testIFs('3;4lywbsdfml');
testIFs('easter egg');
</script>
[/code]
Copy linkTweet thisAlerts:
@felgallOct 21.2006 — That pseudo code is also completely valid Javascript (although most Javascript programmers will always include the optional semi-colons on the end of each statement as well).

You might like to take a look at the source of my Javascript formatter at http://javascript.about.com/library/blformat.htm where I have a Javascript attached to the form that "tokenizes" the Javascript that is entered in order to apply a consistent formatting and colour coding to it.
Copy linkTweet thisAlerts:
@CharlesOct 21.2006 — But if you [i]really[/i] want to get into the nitty-gritty then you [i]must[/i] read http://www.ecma-international.org/publications/files/ecma-st/ECMA-262.pdf .

The converse is even more true, however. If you don't want to get way too far into the same nitty-gritty then you [i]really must not[/i] read that document.
Copy linkTweet thisAlerts:
@JMRKERauthorOct 23.2006 — Thanks for the information toicontien, felgall and charles.

I'll come back after I digest the information and have something more specific to ask.
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...