Conditional Statements Interview Questions


What is a conditional statement in COBOL?

A conditional statement derives a condition's truth value (TRUE or FALSE), and decides the further program execution flow.

What are the conditional statements in COBOL?

The conditional statements are -

  • IF Statement
  • EVALUATE Statement
  • Statements with conditional phrases

IF Statement -

What is significance of IF statement?

IF statement validates a condition to get the truth value and executes the statements under IF when the condition is TRUE.

What are the different IF statements?

IF statements are of three types based on their usage in the program -

  • Simple IF
  • IF...ELSE
  • Nested IF

What is the IF…ELSE statement?

IF...ELSE condition is used to validate a condition and handles both (either TRUE or FALSE) outcomes of the condition.

What is the nested IF…ELSE statement?

IF statement within another IF statement is called as NESTED IF statement.

What is IS NUMERIC clause?

It is used to validate whether the data is numeric or not.

Evaluate Verb -

What is the use of EVALUATE statement?

EVALUATE validates multiple conditions at a time and controls the program flow. It is a shorter form for the nested IF...ELSE and simplifies the logic when multiple choices are available.

How the EVALUATE statement works?

Once the EVALUATE statement execution starts, the following things happen -

  • The conditions are coded with WHEN; if any condition is satisfied, the statements coded under the WHEN are executed, and control transfers to the following executable statement after EVALUATE.
  • If none of the EVALUATE satisfies, the statements coded under WHEN OTHER get executed by default, and control transfers to the next executable statement after EVALUATE.

What are the types of EVALUATE statement?

EVALUATE can be divided logically into the below types based on their usage in the program -

  • Simple EVALUATE
  • EVALUATE TRUE
  • EVALUATE with THRU
  • EVALUATE with grouping multiple WHEN conditions
  • EVALUATE...WHEN with combined conditions

In an EVALUTE statement is the order of the WHEN clauses significant?

Yes

What is the simple EVALUATE?

EVALUATE has only one condition and validates a single variable against multiple values.

What is the EVALUATE TRUE?

In this format, multiple conditions are evaluated instead of checking a variable's value. EVALUATE has a boolean value (TRUE or FALSE), and WHENs have logical expressions.

How to validate range of values in the COBOL program using EVALUATE?

EVALUATE THRU is used to validate the variable with a range of values. The values range should be in ascending order.

Can we group multiple WHEN conditions in EVALUATE statement?

Yes

In an EVALUATE statement, can a complex condition given on a when clause?

Yes

Conditional Expressions -

CLASS condition -

What is the significance of CLASS condition?

CLASS condition tests whether the data in a variable belongs to a specific category of data.

What are class conditions in COBOL?

ALPHABETIC, ALPHABETIC-LOWER, ALPHABETIC-UPPER, NUMERIC, Class-name.

Relation condition -

What is the significance of RELATION condition?

A relation condition compares two operands using relational operators (=, >, <, <=, >=, <>) and returns a boolean value of TRUE or FALSE.

What are the relation conditions in COBOL?

=, >, <, <=, >=, <>

Sign condition -

What is the significance of SIGN condition?

SIGN condition tests the sign (positive, negative, or zero) of the data in numeric variables.

What are the sign conditions in COBOL?

IS POSITIVE, IS NEGATIVE, IS ZERO

Combined condition -

What is the combined condition?

A combined condition is a logical group with two or more conditions.

What are the keywords used in combined conditions are there in COBOL?

AND, OR

Negated Condition -

What is the negated condition?

A condition is negated with the use of the logical operator NOT.

Statements used with IF & EVALUATE -

CONTINUE -

Explain the CONTINUE statement in COBOL?

CONTINUE statement transfers the control to the immediate COBOL statement that comes next in the program flow.

Specify some rules in coding CONTINUE?

  • CONTINUE is allowed to code only in conditional statements like IF, IF...ELSE and EVALAUTE.
  • It satisfies syntactic requirements or improves code readability.

NEXT SENTENCE -

Explain the NEXT SENTENCE statement in COBOL?

NEXT SENTENCE transfers the control to the following COBOL statement immediately after the explicit scope terminator (period - '.') in the flow.

Specify some rules in coding NEXT SENTENCE?

  • NEXT SENTENCE can be coded anywhere in the PROCEDURE DIVISION.
  • It is used to change the execution flow based on the condition.
  • It impacts the program flow by skipping the statements between NEXT SENTENCE and the explicit scope terminator (period—'.').

Common Questions -

What distinguishes NEXT SENTENCE from CONTINUE?

CONTINUENEXT SENTENCE
It transfers the control to the immediate statement that comes next in the program flow. It transfers the control to the following COBOL statement immediately after the explicit scope terminator (period - '.') in the flow.
It is allowed to code only with conditional statements like IF, IF...ELSE and EVALAUTE. It is allowed to code only with conditional statements like IF, IF...ELSE and EVALAUTE.
It doesn't skips any statements. It skips the statements between NEXT SENTENCE and the explicit scope terminator (period—'.').

Frequently Asked Questions -

Explain the objective of using conditional statements in programming?

How to compare if, else, and evaluate statements?

What is the 'IS NUMERIC' clause?
What do you understand by the 'IS NUMERIC' clause in COBOL?

Explain the use of EVALUATE statement?
How do you use the evaluate statement in COBOL?

What procedure do you follow to come out of an EVALUATE statement?

What are common forms of evaluate statements?
How do you use the EVALUATE statement in COBOL, and what are the different types of conditions that can be evaluated?

What is the use of the EVALUATE TRUE statement in COBOL, and how can it be used to implement complex conditional logic?

What is the use of IS ALPHABETIC?

What is the use of IS POSITIVE?

How to code negated condition in the COBOL program?

What are the other statements come up with CONTINUE statement in COBOL?

What are the other statements come up with NEXT SENTENCE statement in COBOL?

What is the difference between CONTINUE and NEXT SENTENCE?
What is the difference between NEXT SENTENCE and CONTINUE statements?
How is the NEXT SENTENCE statement different from CONTINUE statement?
What is the difference between the NEXT SENTENCE and CONTINUE in COBOL programming language?