5. Loop Control Structure - Students Free Notes

Explain different types of loops (for, while, do-while) with syntax and examples.

for loop: Used when the number of iterations is known beforehand. It consists of three parts: initialization, condition, and update. Syntax: for(initialization; condition; update) { // code to execute } Example: for(int i = 1; i <= 5; i++) { printf(“%d “, i); } Output: 1 2 3 4 5 while loop: Executes as long … Read more

Explain the execution of a for loop with a flowchart and example.

A for loop is a control flow statement that repeatedly executes a block of code a certain number of times based on a condition. It is commonly used when the number of iterations is known beforehand. The basic structure of a for loop is: for(initialization; condition; update) { // code to be executed } Initialization: … Read more

What is an infinite loop? Give an example.

An infinite loop is a loop that never terminates because its condition always evaluates to true, or there’s no exit condition defined. It continues to execute indefinitely until it is manually interrupted or the program is terminated. Example of an infinite loop: while(1) { printf(“This is an infinite loop\n”); } The condition 1 is always … Read more

Differentiate between break and continue statements.

The break and continue statements are used to control the flow of execution in loops, but they serve different purposes: break: This statement is used to exit a loop completely, terminating it regardless of whether the loop’s condition has been satisfied. It is often used when a certain condition is met, and there’s no need … Read more

What is a looping structure? Explain for loop with examples.

A looping structure is used to execute a block of code repeatedly based on a certain condition. It allows you to repeat operations without needing to write the same code multiple times. Looping structures help in automating repetitive tasks efficiently. A for loop is generally used when the number of iterations is known beforehand. It … Read more