the while loopthe while loop repeats a statement


The while Loop

The while loop repeats a statement until the test at the top proves false. As an example, here is a function to return the length of a string.

int string_length(char string[])

{

int i = 0;

while (string[i] != '\0') I++;

return(i);

}

The string is passed to the function as an argument. The size of the array is not specified, the function will work for a string of any size. The while loop is used to look at the characters in the string one at a time until the null character is found. Then the loop is exited and the index of the null is returned. While the character isn't null, the index is incremented and the test is repeated.

 

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: the while loopthe while loop repeats a statement
Reference No:- TGS0305482

Expected delivery within 24 Hours