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.#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