C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » C programming language

Print numbers from 1 to N using goto statement in C language

In this post, we will learn how we can print the numbers from 1 to N without using any looping statements like for, while, and do while? Here we will use goto statement?

Prerequisite: syntax and example of goto statement in C, goto statement in C

As we know, goto is used to jump the program's execution to a label (which can be defined anywhere in the scope).

To write this program, we can use goto statement within a condition and can jump program’s execution to the beginning (where number is printing).

Consider the program:

#include <stdio.h>

int main()
	int counter=1;
	int n;
	//enter the value of n (range)
	printf("Enter the value of n: ");
	//define label
	printf("%d ",counter);
	counter++; //increment counter
	//condition & goto statement
		goto START;
	return 0;


Enter the value of n: 10
1 2 3 4 5 6 7 8 9 10 

You may also be interested in...

C/C++ Tips and Tricks...

Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.

Comments and Discussions