Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



What are Flow Control Statements in JavaScript?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 09-02-2010
Member
 
Join Date: Aug 2006
Posts: 209
What are Flow Control Statements in JavaScript?
  

I am very new to the JavaScript. Before this I have done C, C++ and Core Java. Since I am new to JavaScript, I am unknown of many terms. I have recently got an assignment in which I have to explain the Flow Control Statements. Can someone explain me exactly what are Flow Control Statements in JavaScript.?? If you provide me some coding for the same, that would be much better for me to understand,.!! Help me soon as possible.!!

__________________
Blessings to you
Reply With Quote
  #2  
Old 09-02-2010
Member
 
Join Date: Mar 2008
Posts: 349
Re: What are Flow Control Statements in JavaScript?

In JavaScript, you can define variables and manipulate them. A basic execution unit in JavaScript is known as Statement. The following are some basic things that gets applied to the statement :
  • You must end the statement with semicolon (.
  • The statements are not ended by the line breaks. In simple words, you can say that, a single statement can be written in multiple lines, and multiple statements can be written in a single line.
  • A statement can be simple expression, like a single literal, or a complex expression with assignment operators.
  • The key words that mainly involved in a statements are "if", "while", "var", "break", etc.
  • You can also use the multiple statements which can be grouped together to form a statement block in the format.
  • You can use the comments anywhere in the statements.
Reply With Quote
  #3  
Old 09-02-2010
Member
 
Join Date: Mar 2008
Posts: 672
Re: What are Flow Control Statements in JavaScript?

You can check the following example, so that you can easily understand how to use the Flow Control Statements in JavaScript..!! Here is the code :
HTML Code:
<html>
<head><title>Statements</title></head>
<body>
<script type="text/javascript">
   var a,b,c; 

   a=4, b=16, c=36;
   a*a; b*b; c*c;

   { 
      a *= a; 
      b *= b;
      c *= c;
   }

   if (true) 
      document.write("9 statements in total.");
</script>
</pre>
</body>
</html>
Reply With Quote
  #4  
Old 09-02-2010
Member
 
Join Date: May 2008
Posts: 2,291
Re: What are Flow Control Statements in JavaScript?

I have provided you with an example of the "if" statements, which is a type of the Statement. The example is little bit long but very easy to understand. Just have a glance on the following example :
HTML Code:
<html>
<head><title>Using the If Statements</title></head>
<body>
<pre>
<script type="text/javascript">
   document.write('\n');
   var is_december = true;
   if (is_december) document.write("Merry Christmas!\n");

   document.write('\n');
   var is_log_on = true;
   if (is_log_on) {
      document.write("Open the log file.\n");
      document.write("Write the log message.\n");
      document.write("Close the log file.\n");
   }
  
   document.write('\n');
   var is_admin = false;
   if (is_admin) {
      document.write("Display the edit button.\n");
      document.write("Display the add button.\n");
   } else {
      document.write("Display the view button.\n");
   }
  
   document.write('\n');
   var week_day = 4;
   var open_hours;
   if (week_day == 0) {
      open_hours = "closed";
   } else if (week_day >= 1 && week_day <= 5) {
      open_hours = "open from 9:00am to 6:00pm";
   } else if (week_day == 6) { 
      open_hours = "open from 9:00am to 4:00pm";
   } else {
      open_hours = "undefined";
   }
   document.write("The library is " + open_hours + ".\n");
</script>
</pre>
</body>
</html>
Reply With Quote
  #5  
Old 09-02-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: What are Flow Control Statements in JavaScript?

The "switch ... case" statements are also important in the Statements. It is very commonly used when you have to include many conditions at a time. You will get the point better, if you have a look on the following example :
HTML Code:
<html>
<head><title>Examples of Switch Case Statements</title></head>
<body>
<pre>
<script type="text/javascript">

   var week_day = 4;
   var day, open_hours;
   switch (week_day) {

      case 0:
         day = "Sunday";
         open_hours = "closed";
         break;

      case 1:......
      case 2:......
      case 3:.....
      case 4:.....
      case 5:.....
         day = "a weekday";
         open_hours = "open from 9:00am to 6:00pm";
         break;

      case 6:
         day = "unknown";
         open_hours = "open from 9:00am to 4:00pm";
         break;

      default:
         day = "unknown"
         open_hours = "undefined";
   }
   document.write('\n');
   document.write("Today is " + day + ".\n");
   document.write("The library is " + open_hours + ".\n");
</script>
</pre>
</body>
</html>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What are Flow Control Statements in JavaScript?"
Thread Thread Starter Forum Replies Last Post
Error Control and flow control in TCP/IP? Diellza Networking & Security 5 07-01-2011 08:36 AM
How to use flow control in ASP 3.0 Appaji Software Development 4 06-03-2010 01:59 AM
JavaScript for Dropdown HTML control Dilbert Software Development 4 06-02-2010 03:32 AM
Difference between DML statements and DDL statements Prashobh Mallu Software Development 5 11-01-2010 12:07 PM
Javascript Control Bar Issue RAJalias Software Development 3 25-11-2009 12:31 PM


All times are GMT +5.5. The time now is 09:27 PM.