Simple Looping Example in C (While)

This code demonstrates the use of both a while loop and a do-while loop in C programming. The program repeatedly prompts the user to input a value for X until they enter 0, showcasing two different looping constructs.
 avatar
AdhamElshabasy
c_cpp
a month ago
229 B
1
Indexable
C Basics
#include <stdio.h>

int main() {
	
	int x = 1;
	
	while(x != 0) {
		printf("Enter X (while): ");
		scanf("%d", &x);
	}
	
	do {
		printf("Enter X (do-while): ");
		scanf("%d", &x);
	} while(x != 0);
	
	return 0;
}
Leave a Comment