Category Archives: C Loop Control Statements

C Go To Statement

C goto statement

The c goto statement is used to alter the normal execution of a program and transfer control to a labeled statement in the same program. We can have multiple goto and label statements in a c program. The goto statement is followed by a label name. The label is an identifier, which can be any plain text. It can be set anywhere in a c program. The label can be defined above or below to go to the statement. When a goto statement is encountered the compiler transfers the control to a label: specified with a goto statement. Then compiler begins execution from there.

GoTo Statement Syntax

Below is the general syntax of the goto statement in c programming:

Syntax:-

Program Structure:-

goto Statement Example

Below is a simple example to demonstrate the use of the goto statement in c programming:

Example:-

Output:-

c-goto-statement

C Continue Statement

C Continue Statement

It will give you a way to skip over the current iteration of any loop. When a continuous statement is encountered in a loop, the rest of the statements in the loop body for the current iteration ends and returns the program execution to the very first statement in the loop body. It does not terminate the loop rather continues with the next iteration.

Continue Statement Flow Diagram

c_continue_flow_diagram

Continue Statement Syntax

Below is the general syntax of the continue statement in c programming:

Syntax:-

Continue Statement Example

Below is a simple example to demonstrate the use of the continue statement in c programming:

Example:-

When we run the above C program, we will see the following output –

Output:-

c-continue-statement

As you can see when ctr == 5, the continue statement is executed which causes the current iteration to end, and the control moves on to the next iteration.

C Break Statement

The c break statement inside any loop gives you a way to break or terminate the execution of the loop containing it and transfers the execution to the next statement following the loop. It is always used with a c if-else statement.

Break Statement Flowchart In C

c-break-statement-flowchart

Break Statement Inside Loops

C Break Statement Flow Diagram

Syntax Of Break Statement

Below is the general syntax of break statement in c programming:

Syntax:-

Break Statement Example

Below is a simple example to demonstrate the use of break statement in c programming:

Example:-

In the above program, the variable count is initialized as 0. Then a while loop is executed as long as the variable count is less than 10. Inside the while loop, the count variable is incremented by 1 with each iteration (count = count + 1). Next, we have an if statement that checks the variable count is equal to 5, if it returns TRUE causes the loop to break or terminate. Within the loop, there is a printf statement that will execute with each iteration of the while loop until the loop breaks. Then, there is a final printf statement outside of the while loop. When we above c program, our output will be as follows –

Output:-

c-break-statement