The for statement is a loop statement which consists of three components namely initialization, expression and iteration.
Syntax:
for (initialization; expression; iteration) {
statement;
}
-----
-----
Below is the sequence of operation we do in for loop:
Syntax:
for (initialization; expression; iteration) {
statement;
}
-----
-----
Below is the sequence of operation we do in for loop:
- Do initialization
- Evaluate the expression. If the expression evaluates to be false, then go to step 6. Basically, for loop execution would end, program control would transfer to the statement next to for loop and the statements inside for loop won't get executed.
- If the expression evaluates to be true, then the statements inside the for loop will get executed.
- Once all statements inside for loop is executed, then iteration is done
- Continue from step 2
- End for loop execution
Example C program using "for Loop":
#include <stdio.h> int main() { int i; for (i = 1; i <= 10; i++) { /* * i = 1 => initialization * i <= 10 => Expression * i++ => iteration */ printf("%d\n", i); // execute this statement until i is less than or equal to 0 } return 0; }
Output:
jp@jp-VirtualBox:~/$ ./a.out
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
Dell Laptop Service center are giving repair service at the door. We should high quality Dell out of warranty Laptop Repair, removal of virus, screen removal, wireless network set up, battery removal, motherboard replacement to several other are offered at budget friendly price and it’s Negotiable. We can fix them all in time by our well experience and certified technicians. If you want to repair your laptop in front of your eyesight, than you may call us: 7217871051
ReplyDeleteAmazing content, you can find more content related to C Programming here.
ReplyDelete