Posted: . At: 2:53 PM. This was 9 years ago. Post ID: 8005
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to include code inside a loop in C.


This loop I wrote in C enables if statements inside a loop. This could be a useful thing to know.

#include <stdio.h>
 
int main(void)
{
	int k;
 
	for (k = 0; k < 16; k++) {
		printf("*                          *\n");
		if (k == 4 || k == 12) {
			printf("\n\t\t-\n");
		}
		if (k == 8) {
			system("who am i");
		}
	}
 
	return 0;
}

This section of code for example, this will check whether k equals 4 or 12.

if (k == 4 || k == 12) {
			printf("\n\t\t-\n");
}

And this code will check whether k equals 8.

if (k == 8) {
			system("who am i");
}

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.