Logic Series-4 Iterators and Conditional Statement

Iterators and Conditional Statements

  

In our last session we have seen the operator’s concept and type of the operator. In today’s session we will see the two most important concepts i.e. Loops (iterators), Conditional Statements.

Iterators: 

What are iterators?

Iterators are nothing but the continuous chain of something. It’s like a cycle, it has a starting point an end point and a way that how it will go from starting point to the end point as how much steps it will take at a time to cover that distance. We will see an example for this.

Declare I

Initialization I =1; -- starting point

Loop: I <=10; -- End Point 

I=I+1; -- steps it will take


In above example we have declare the variable I, we have initialized as it will start from 1, the End point is 10 as it will stop at 10 and it will take 1 step at a time to cover this.

In Any programming Language this concept will cover under Loop concept and those are somehow similar in structure in most of the programming language. We will an example of one of the popular loop – while Loop

Declaration of Variable -- int I; 

Initialization of Variable – I=1;

Condition – while (I<=10) {

Processing of condition – Display I;

How it will proceed -- I=I+1; 

}



  

Conditional Statements:

As the term suggest it works on the conditions, If certain condition comes then how our code will works or else how it will behave  we just have to define this.

Primary Example of the conditional statements are:

1) If statement.

2) If – else statement.

3) Switch case Statement.

We will one by one significance of each statement.

1) If Statement – This works on the single Condition as if given condition is satisfied then only this condition will work or else it will not execute. 

Ex. If the condition is given the person can drive if the persons age is above 18 then it will be something like this.

If (age>18)

{

Print (“person can drive”);

}

It will not work what if the age is not below 18.

2) If – else Statement – This statement will work on else perspective of the condition also.

Like what if our given condition will not work it will also works on that part.

Ex. If the condition is given the person can drive if the person’s age is above 18 or else it will display that person cannot drive then it will be something like this.

If (age>=18)

{

Print (“Person can drive”);

} else {

Print (“Person cannot drive”); 

}

We can surely merged more than one if-else with multiple logical operators for multiple  

Conditions and we will definitely see those in our future ventures.  

3) Switch case Statement – This Statement works on selecting an exact condition from the multiple given conditions.

Ex. The Most common Example of this is that whenever we call to certain customer care call centre and they ask us to choose a single option from multiple that can be selecting a language option or anything. We will see the Language Option.

Switch (case)

{

Case 1: print (“To select an English Language”);

Break;

Case 2: print (“To select a French Language”);

Break;

Case 3: print (“To select a Hindi Language”);

Break;

Default: print (“To go to the Main Menu”);

}


SO these are some Easy but important concepts of Data Structure, one can definitely wanted to make this concepts strong if they wanted to learn any programming Languages.

We will see the Function concepts in our next session.


-- EduWithUs Team.