how to read logic / looping from this sourcode

0 votes
asked May 13 by Satriadi Lumban Gaol (120 points) 1 flag
#include <stdio.h>

int main()
{
    int x,y;
    for(x=0; x<9; x++){
        for(y=0; y<9; y++){
            if(x==0){
                printf("*");
            }else if(x==8){
                printf("*");
            }else if(y==0){
                printf("*");
            }else if(y==8){
                printf("*");
            }else if(x==4){
                printf("*");
            }else{
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}

1 Answer

0 votes
answered May 15 by LiOS (3,880 points)
Flow of code goes:

- Check first for loop, if true, move on

- Check second for loop, if true, process all the if, elseif, else statements

- Goes back to second for loop. Until second for loop is false, will repeat stage 2.

- When second for loop is false. Go back to first for loop, increment and check if true, if so repeat... until first for loop is false
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...