Sentinel Loop C++

Expression is a valid C expression that evaluates to true or false or a numerical value. Statement is a simple or compound C statement (with all semi-colons included). This is a pre-test loop. This means that the condition in expression is checked before the body of the while loop. Event-controlled loops are used to read, write, and process data. Each iteration of the loop represents an action on a data object. Often when reading data either from a file or from standard input we have a sentinel or end-of-file controlled loop. The sentinel value is used to signal that there is no more data to be read or processed.

  • C Programming Tutorial
  • C Programming useful Resources
  • Selected Reading
Sentinel Loop C++

Sentinel Loop Variable C++

The break statement in C programming has the following two usages −

C++ Counting Loop

While
  • When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.

  • It can be used to terminate a case in the switch statement (covered in the next chapter).

If you are using nested loops, the break statement will stop the execution of the innermost loop and start executing the next line of code after the block.

Syntax

The syntax for a break statement in C is as follows −

Flow Diagram

Example

When the above code is compiled and executed, it produces the following result −

Sentinel Controlled While Loop C++

  • C Programming Tutorial
  • C Programming useful Resources
Loop
  • Selected Reading
Sentinel Loop C++

The break statement in C programming has the following two usages −

  • When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.

  • It can be used to terminate a case in the switch statement (covered in the next chapter).

If you are using nested loops, the break statement will stop the execution of the innermost loop and start executing the next line of code after the block.

Syntax

The syntax for a break statement in C is as follows −

Sentinel Control Loop C++

Flow Diagram

Example

C++ Sentinel Value

When the above code is compiled and executed, it produces the following result −