D is for Digital by Kernighan Brian

D is for Digital by Kernighan Brian

Author:Kernighan, Brian [Kernighan, Brian]
Language: eng
Format: epub
Tags: Computers / General
Publisher: Brian W. Kernighan
Published: 2012-02-03T20:00:00+00:00


7.5 Conditionals

This next example does a slightly different job, finding the largest of all the numbers that were provided. It's an excuse to introduce another control-flow statement, if-else, which appears in some form in all high-level languages as a way to make decisions; it's in effect a general-purpose version of IFZERO. JavaScript's version of if-else is the same as in C.

var max, num;

max = 0;

num = prompt("Enter new value, or 0 to end");

while (num != 0) {

if (parseInt(num) > max) {

max = num;

}

num = prompt("Enter new value, or 0 to end");

}

alert("Maximum is " + max);



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.