FOR MORE & MORE TECHNICAL INTERVIEW QUESTIONS …, Join Our Group nowhttp://in.groups.yahoo.com/group/knowledge-base/join/Introduction
Unless you already understand the basics of “branching and looping” you should read The previous tutorial Controlling Program Flow in Plain English.
You have arrived at the point where programming becomes more challenging and if you have a programmers mind" far more interesting, so enjoy.
This is the stage where you have to start thinking, how can I code a particular aspect of my project.
This is the point where you start to develop your personel style.
Up to this tutorial your programs have been sequential or linear statements being executed one after the other. Now you are going to be introduced to constructs that alter that linear progression.
The new functions that are in this tutorial allow either branching or looping.
You will note that a pair braces { } are used with these constructs.
The { denotes the start of the first statement within the construct.
The } denotes the end of the last statement in the construct.
Tip: Take particular note of how braces { } are used.
Tip: Note where ; is NOT used in these constructs.
Tip: As you read my tutorials, books, course material etc., copy a few samples of each construct showing the use of braces and where ; is used or not used, for future reference. Pay particular note of the if ( ) ... else construct, and where constructs are nested. That it where a construct is placed within the braces of another construct. You can have several layers of nesting. A nested example is given later on this page.
Top of Page
Branching
Branching statements allow different sections of code to be executed, or not executed depending on some condition being either true or false.
The following constructs contain branching.
From the previous tutorial, “Do you require sugar” is an example
.
if, if ... else, while, do, switch, and for constructs.
All these construct contain a test. Think of test as a question. Example “Is the number less than 3”
All tests contain a comparison / conditional operator such as equal to, less than, or greater than. These comparison or conditional operators are listed below.
Top of Page
Looping
Looping constructs are used to repeat a section of code a number of times, depending on some condition being either true or false.
To take the previous lesson a little further, if somebody wanted 3 teaspoon full of sugar the you could repeat adding 1 spoonful of sugar 3 times.
Iteration is the correct term to use for this looping process
The looping constructs are while, do, for constructs.
Again these contructs contain a test and a a comparison / conditional operator