+ 3
What is for loop
8 Answers
+ 9
FOR loop Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable. You can use one or more loop inside any another while, for or do..while loop.
_OR_
A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
__An Example__
***************************************
#include <iostream>
using namespace std;
int main () {
// for loop execution
for( int s = 10; s < 16; s = s + 1 ) {
cout << "value of s: " << s << endl;
}
return 0;
}
************
OUTPUT for above example :
value of s: 10
value of s: 11
value of s: 12
value of s: 13
value of s: 14
value of s: 15
****************************
HOPE this helps.. :)
+ 1
It consists of a variable assignment, a conditional statement against that variable, and an increment to the variable. It allows single or multiple instructions to be run a given number of times. It is used alongside arrays to loop through every element in the array (as arrays are 0-based and we can assign the variable in the for loop to start at 0) by using the variable we assign in the for loop as our index. When the compiler reaches the end of the block inside of a for loop it automatically increments the variable, then checks the condition against the variable and then re-runs the instructions in the block if the condition is still met. For loops can use pre-existing variables, however it is common practice to declare the variable inside of the assignment of the variable in the for loop, because when the for loop is done, that variable name is not needed by the program anymore. Sometimes, however, the program will make use of the variable after the for loop is done, which means it is necessary to declare the variable outside of the for loop and use the variable for the assignment, condition, and increment.
+ 1
Imagine you have to repeat an statement one after another and stop it when condition falls false.
The loop do the same he repeats itself one after another till the condition becomes false.
In for loop all initialisation, condition and increment or decrement is contained in one so it is so most preferred by and used by good programmers.
The syntax of for loop is:
for(initialisation; condition; increment or decrement)
{
content
}
The important thing in for loop is if u don't want to do initialisation u do above as declaration cum initialisation ,the two semicolon is important.
0
the for loop is a statement which is used to create loops in your program. if you want to understand them the easiest way is to read and use them
0
The variable initialization allows you to either declare a variable and give it a value or give a value to an already existing variable. Second, the condition tells the program that while the conditional expression is true the loop should continue to repeat itself. The variable update section is the easiest way for a for loop to handle changing of the variable. It is possible to do things like x++, x = x + 10, or even x = random ( 5 ), and if you really wanted to, you could call other functions that do nothing to the variable but still have a useful effect on the code. Notice that a semicolon separates each of these sections, that is important. Also every single one of the sections may be empty, though the semicolons still have to be there. If the condition is empty, it is evaluated as true and the loop will repeat until something else stops it.Â
0
for( ; ; )
for loop is repeated execution of
{
statement
or
statements
..........................
}
till the ( ; condition ; ) arise
you can define the incriminat or detriment in ( ; ; here )
loop can be terminat by (break;) any time
otherwise it will terminat when ( ; condition ; )
you can place multiple conditions
on single for loop
using multiple conditions you can marz
many loops into single loop
0
for loop repeat a statement until the condition is true
- 2
it is used if u have different choices