This loop is best used when the number of repetitions is unknown.
while loop
The index number where arrays start in C.
0
This data type stores a single character.
char
This statement immediately exits a loop.
break
int i = 1;
while(i <= 3){
printf("%d ", i);
i++;
}
1 2 3
This loop is commonly used when counting from 1 to 10.
for loop
The correct declaration for an integer array with 5 elements.
int arr[5];
In C, a string is stored as this type of structure.
character array
This statement skips the remaining code in the current iteration.
continue
for(int i = 5; i > 0; i--){
printf("%d ", i);
}
5 4 3 2 1
This loop guarantees the code will run at least once.
do-while loop
This type of structure stores multiple values of the same data type.
array
This character marks the end of a string.
\0 (null character)
This statement is often used to stop input if a condition is met.
break
for(int i = 1; i <= 5; i++){
if(i == 3)
break;
printf("%d ", i);
}
1 2
This part of a loop increases or decreases the counter value.
increment/decrement (i++ or i--)
The index of the last element in int a[10];
9
This function safely reads a string including spaces.
fgets()
When this statement executes, the loop jumps directly to the next iteration.
continue
for(int i = 1; i <= 5; i++){
if(i == 3)
continue;
printf("%d ", i);
}
1 2 4 5
This happens if the condition of a while loop is false at the beginning.
the loop does not run
This loop is most commonly used to input values into an array.
for loop
This is NOT a valid string declaration in C.
string name;
These two statements are commonly used for controlling loops.
break and continue
int arr[3] = {10,20,30};
printf("%d", arr[1]);
20