---
title: "GOTO types; sum of series program"
subject: "Computer Programming"
chapter: 11
key: "semester_1/computer_programming:fortran-goto-types-series"
source: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-goto-types-series
site: BCT Engineering
---

# GOTO types; sum of series program

Computer Programming · Chapter 11: Programming Language: FORTRAN

- Asked in: 2072 Kartik, 4+4 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-goto-types-series
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-11

## Question

Explain different types of goto statements in FORTRAN programming with suitable example. Write a program to read n from user and display the sum of following series till nth terms: 1+(1+2)+(1+2+3)+(1+2+3+4)+...........n

## Short answer

Unconditional GO TO jumps to one label. Computed GO TO selects a label from a list by integer value. Assigned GO TO uses a label stored via ASSIGN. The series sum program reads n, computes sum = 1 + (1+2) + (1+2+3) + ... up to n terms using a loop: accumulate term T = T + i and add to S. For n=4, sum=20.

## Answer

#### Types of GO TO statements
1. **Unconditional GO TO:** `GO TO 100` always jumps to statement 100.
2. **Computed GO TO:** `GO TO (10, 20, 30), K` jumps to the K-th label in the list (1st label if K = 1, etc.).
3. **Assigned GO TO:** a label is first stored in an integer variable with `ASSIGN`, then used.

```fortran
      ASSIGN 40 TO LBL
      GO TO LBL, (40, 50)
```
(Related: the arithmetic IF `IF (X) 10, 20, 30` is also a three-way jump, by the sign of X.)

Example of computed GO TO:
```fortran
      READ *, K
      GO TO (10, 20), K
      PRINT *, 'OTHER'
      STOP
   10 PRINT *, 'ONE'
      STOP
   20 PRINT *, 'TWO'
      END
```

#### Sum of the series 1 + (1+2) + (1+2+3) + … up to n terms
The i-th term is T = 1 + 2 + … + i. Each new term is the previous term plus i, so the program keeps a running term `T` and adds it to the sum `S`. The loop is made with an IF and a GO TO.

```fortran
      PROGRAM SERIES
      INTEGER N, I, T, S
      PRINT *, 'ENTER N'
      READ *, N
      S = 0
      T = 0
      I = 1
   10 IF (I .LE. N) THEN
         T = T + I
         S = S + T
         I = I + 1
         GO TO 10
      END IF
      PRINT *, 'SUM OF THE SERIES = ', S
      STOP
      END
```

**Sample:** N = 4 gives 1 + 3 + 6 + 10 = **20** (the formula n(n+1)(n+2)/6 = 4·5·6/6 = 20 agrees).

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which are the three types of GO TO in the answer?
   A. Unconditional, computed and assigned
   B. Simple, nested and looped
   C. Arithmetic, logical and block
   D. Forward, backward and circular
   Answer: A. The three types are unconditional GO TO, computed GO TO and assigned GO TO. (Key point: Types of GO TO)

2. What must be done before an assigned GO TO is used?
   A. The label is stored in an integer variable with ASSIGN
   B. The program must be compiled twice
   C. Declare the variable as LOGICAL
   D. Use a DO loop
   Answer: A. ASSIGN 40 TO LBL stores a label in an integer variable which GO TO LBL, (40, 50) then uses. (Key point: Assigned GO TO)

3. How does the program build terms of 1 + (1+2) + (1+2+3) + ...?
   A. Each term is the previous term plus i, added to the running sum
   B. Each term is i squared
   C. Each term is i factorial
   D. Each term is i/2
   Answer: A. The i-th term T = 1 + 2 + ... + i equals the previous T plus i, so T = T + I then S = S + T. (Key point: Series logic)

4. For N = 4, what is the sum of the series?
   A. 10
   B. 20
   C. 30
   D. 24
   Answer: B. 1 + 3 + 6 + 10 = 20, which matches n(n+1)(n+2)/6 = 20. (Key point: Series check)

## Related in Computer Programming

- [Read records until end; show nth record](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-worker-nth-record) — Computer Programming, chapter 10, asked 2×
- [Sum of two matrices in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-matrix-sum) — Computer Programming, chapter 11
- [Series sum 1/1¹+1/2²+… in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-series-sum-1-over-n) — Computer Programming, chapter 11
- [nth Fibonacci term prime check](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afibonacci-nth-prime) — Computer Programming, chapter 6
- [Structure of a FORTRAN program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-structure) — Computer Programming, chapter 11, asked 5×
- [Sum of series Σ1/n²](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aseries-sum-1-n-squared) — Computer Programming, chapter 5

## Related in other subjects

- [C program: sum of two 8-bit BCD numbers](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-bcd-sum-c) — Embedded System, chapter 9
- [Series sum using Z-transform](https://www.bctengineer.com/question.md?key=semester_3%2Fmathematics_iii%3Aseries-sum-using-z-transform) — Mathematics III, chapter 3
- [Series programming of a digital controller](https://www.bctengineer.com/question.md?key=semester_6%2Fdigital_control_system%3Aseries-programming-controller) — Digital Control System, chapter 4, asked 4×
- [Series programming of a third-order transfer function](https://www.bctengineer.com/question.md?key=semester_6%2Fdigital_control_system%3Aseries-programming-z-plus-1) — Digital Control System, chapter 4, asked 2×
