Results 1 to 5 of 5

Thread: What are Flow Control Statements in JavaScript?

  1. #1
    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

  2. #2
    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.

  3. #3
    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>

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    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>

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    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>

Similar Threads

  1. Error Control and flow control in TCP/IP?
    By Diellza in forum Networking & Security
    Replies: 5
    Last Post: 07-01-2011, 09:36 AM
  2. How to use flow control in ASP 3.0
    By Appaji in forum Software Development
    Replies: 4
    Last Post: 06-03-2010, 02:59 AM
  3. JavaScript for Dropdown HTML control
    By Dilbert in forum Software Development
    Replies: 4
    Last Post: 06-02-2010, 04:32 AM
  4. Difference between DML statements and DDL statements
    By Prashobh Mallu in forum Software Development
    Replies: 5
    Last Post: 11-01-2010, 01:07 PM
  5. Javascript Control Bar Issue
    By RAJalias in forum Software Development
    Replies: 3
    Last Post: 25-11-2009, 01:31 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,699,289.21861 seconds with 17 queries