For Loop in CPP

For Loop in C++ Execute a sequence of statement multiple times until the certain condition is fulfilled.For loop is iteration statement. It is also called counter controlled loop. It is the most flexible loop. That is why, it is the most frequently used loop by the c++ programmers.

When we write C++ program, there may be situation when we need to execute a set of instruction several number of times. C++ provides various control structure that all for more complicated execution path.
Loop
According to dictionary definition loop is set of instructions that repeat themselves until the certain condition is fulfilled. It is also known as looping statement or loop. It is also known as iterative statement or repetitive structure.
Loops are basically used for two purposes:
  • ·       To execute a statement or number of statements for a specified number of time. For example, a user may display his name or email on screen for 5 times.
  • ·       To use a sequence of values. For example , a user may display a set of natural numbers from 0 to 50.

There are many types of Loops or iteration statement in C++.
  1. For loop
  2. While Loop
  3. Do-while Loop


For Loop definition in C++
Execute a sequence of statement multiple times until the certain condition is fulfilled.For loop is iteration statement. It is also called counter controlled loop. It is the most flexible loop. That is why, it is the most frequently used loop by the c++ programmers.
Syntax of For Loop
For (initialization statement; test expression; update expression)
{
//statement
}
Syntax 2
For(variable initialization; condition; variable increment )

Initialization statement: it specifies the starting value of counter variable. One or many variables can be initialized in this part. To initialize many variables each variable is separated by comma.
Condition or test expression: The condition is given as a relation expression. The statement is executed only if the given condition is true. If the condition is false, the statement is never executed.
Increment or decrement or Update expression: The part of loop specifies the charge in counter variable after each execution of loop. To change many variables, each variable must be separated by commas.
Statement: statement is the instruction that is executed when the condition is true. Statement are given in braces if they are two or more.
{
}

For loop with Example in borland C++


#include<iostream> //header file for cout and cin
#include<conio>
int main ()        //main function
{              
int a;
for(int a=0; a<=10; a++)        //for(For (initialization; test expression; update expression))
{

cout<<"\n"<<a;                    // statement or loop body
}
getch ();     //getcharacter
return 0;
}




Explanation

Working of ‘For’ loop in C++

The number of iteration depends on the initialization, condition and increment/decrement parts. The initialization part is executed only when control enters the loop. After the initialization, the given condition is evaluated. If it is true, the control enters the body of loop and executes all statement in it. Then the increment part is executed that changes the counter variables. The control again moves to condition part. This process is continues while the condition remain true. The loop is terminated when the condition becomes false.


COMMENTS

BLOGGER: 2
Loading...
Name

andriod.computer trix,1,Blogging,1,Cpp Program,1,CppTutorial,12,create viruse,1,cyber security,2,fb trix,1,gmailtrix,1,laptop screen shot,1,Mobilink,1,notepad tricks,1,notepad viruse,1,PCSREEN SHOT,1,Search engine optimization (SEO),1,seo,1,software,1,Technology,6,tips,1,visitor.seo traffic,1,
ltr
item
Computer Tech Articles: For Loop in CPP
For Loop in CPP
For Loop in C++ Execute a sequence of statement multiple times until the certain condition is fulfilled.For loop is iteration statement. It is also called counter controlled loop. It is the most flexible loop. That is why, it is the most frequently used loop by the c++ programmers.
https://2.bp.blogspot.com/-XOR5ukQpPYo/WNP-FmHi8CI/AAAAAAAAA_w/yoYGUMR3ml8Gv_saMzvlnM-nS8ehOmqmQCLcB/s400/for%2Bloop%2Bprogram.PNG
https://2.bp.blogspot.com/-XOR5ukQpPYo/WNP-FmHi8CI/AAAAAAAAA_w/yoYGUMR3ml8Gv_saMzvlnM-nS8ehOmqmQCLcB/s72-c/for%2Bloop%2Bprogram.PNG
Computer Tech Articles
https://rbatec.blogspot.com/2017/03/for-loop-Cpp.html
https://rbatec.blogspot.com/
https://rbatec.blogspot.com/
https://rbatec.blogspot.com/2017/03/for-loop-Cpp.html
true
8514118360251607171
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy