While loops allow you to run a certain piece of code several times

Syntax


while(test){
     code to run
}



As long as the test remains true, the code will keep repeating


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int tuna = 1;

    while(tuna < 5){
        printf("tuna is now %d \n", tuna);
        tuna++;
    }

    return 0;
}



Double a penny


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int day = 1;
    float amount = .01;

    while(day <= 31){
        printf("Day:%d \t Amount:$%.02f \n", day, amount);
        amount *= 2;
        day++;
    }

    return 0;
}