Monday, May 6, 2013

Control Statement

control Statements are used to create special programme features such as logical test, loopoing and branches. An example of control statement is 

    for(i=0;i<=n;i++)
    { sum+=i }

This means that "i" is a number which starts from 0 and ends at a number "n" which may be given to computer manually and "sum+=i" means computer has to sum present value of i with the previous.For example 
         for i=0   sum=0
         for i=1   sum=0+1=1
         for i=2   sum=1+2=3
         for i=3   sum=3+3=6
         for i=4   sum=6+4=10 and so on.

Note:- Here "sum" itself does not means to sum a value. It is used to keep in mind easily. It can be written in other format as "x+=i".      

No comments:

Post a Comment