ELEVATE YOUR BUSINESS WITH

Limitless customization options & Elementor compatibility let anyone create a beautiful website with Valiance.

For Loop in C

SELECT * FROM `itio_tutorial_master` WHERE `tutorial_menu`='28' AND `tutorial_submenu`='1646' AND `tutorial_status`=1 LIMIT 1

For Loop in C

The for loop in C is a control structure used to repeat a block of code a specific number of times. It’s ideal when you know how many times you want to loop. ??


? Basic Syntax

c

#include <stdio.h>int main() { for (int i = 1; i <= 5; i++) { printf("i = %d\n", i); } return 0;}

Output:

ini

i = 1i = 2i = 3i = 4i = 5


? Breakdown of Components


PartDescription
InitializationHappens once at the start (int i=0)
ConditionChecked before each loop (i <= 5)
IncrementRuns after each loop (i++)


? Decrementing Example

c

for (int i = 5; i >= 1; i--) { printf("%d ", i);}

Output: 5 4 3 2 1


?? Infinite Loop

If you omit the condition:

c

for (;;) { // runs forever unless you break}


? Nested For Loop

c

for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 2; j++) { printf("i=%d, j=%d\n", i, j); }}


? Useful With Arrays

c

int nums[] = {10, 20, 30};int size = sizeof(nums) / sizeof(nums[0]);for (int i = 0; i < size; i++) { printf("%d ", nums[i]);}

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql