Basic for Loop-Programm

Basic for Loop-Programm

Jede Schleife besteht aus drei Teilen in einer Sequenz

  1. Initialisierung :Wird verwendet, um die Schleifenvariable zu initialisieren.
  2. Zustand :Es wird nach jeder Iteration als Einstiegspunkt in die Schleife überprüft.
  3. Aktualisierung :Inkrementieren der Schleifenvariable, um die Schleife schließlich zu beenden, wenn die Schleifenbedingung nicht erfüllt wird.

Denken Sie daran, dass die Schleifenbedingung die bedingte Anweisung überprüft, bevor sie erneut eine Schleife durchläuft.

Syntax:

for(initialization, condition, incrementation)
{ 
    code statements;
}

Unten ist ein einfaches Programm auf for Schleife.

Hier ist das C-Tutorial, das for erklärt Schleife → For-Schleife in C

#include<stdio.h>

int main()
{
    printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");

    /* 
        Always declare the variables before using them 
    */
    int i = 0;  // declaration and initialization at the same time


    for(i = 0; i < 10; i++)
    {
        printf("i = %d\n", i);

        /*
            consequently, when i equals 10, the loop breaks.
            i is updated before the condition is checked-
            hence the value of i after exiting the loop is 10 
        */
     }

    printf("\n\The value of i after exiting the loop is %d\n\n", i);
    
    printf("\nRemember that the loop condition checks the conditional statement before it loops again.\n\n");
    
    printf("Consequently, when i equals 10, the loop breaks.\n\n");
    
    printf("i is updated before the condition is checked- hence the value of i after exiting the loop is 10 .\n\n");
    
    printf("\n\n\t\t\tCoding is Fun !\n\n\n");
    return 0;
}

Ausgabe: