While loop
#include <stdio.h>
int main() {
int i = 1;
while (i <= 5) {
printf("Value of i: %d\n", i);
i++;
}
return 0;
}
Include the standard input-output library.
Define the
main
function.Declare and initialize an integer variable
i
with the value 1.Start a
while
loop with the conditioni
less than or equal to 5.Inside the loop, print the value of
i
using theprintf
function.Increment the value of
i
by 1 using thei++
increment operator.End the
while
loop.Return 0 to indicate successful execution of the program.