3

My friend is preparing for the some bank exam. And the question asked was:

What are the control statement below?

Options
1. `if` and `switch`
2. `break` and `if`
3. `if` and `while`
4. `break` and `continue`

and correct answer marked was 1

I believe all the options are correct?

Is my choice true?

Is there is any difference between them?

chqrlie
  • 131,814
  • 10
  • 121
  • 189
VINOTH ENERGETIC
  • 1,775
  • 4
  • 23
  • 38

6 Answers6

4

It looks like whoever set the exam has invented their own terminology. "Control statement" is not an official term in either C or C++.

if and switch are selection statements.

while is an iteration statement (along with do and for).

break and continue are jump statements (along with return and goto).

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
  • 1) "if,switch, while" are worked on condition and make selection on that condition. 2)"break,continue" are control statements that can change flow of execution and "goto" aslo works same,and all known as jump statements 3) on point 1,2 i can say answer must be (4)->break and continue. – Vinod Patidar Mar 28 '14 at 19:03
3

The terminology is incorrect since the standard does not define a term control statement but since 1 was indicated as the correct answer then what they should have said was selection statements.

The C99 draft standard defines the following set of statements which cover those listed in your question, selection statements are if and switch from section 6.8.4 Selection statements:

selection-statement:
  if ( expression ) statement
  if ( expression ) statement else statement
  switch ( expression ) statement

break and continue are jump statements section 6.8.6 Jump statements:

jump-statement:
  goto identifier ;
  continue ;
  break ;
  return expressionopt ;

and while is an iteration statement section 6.8.5 Iteration statements:

 iteration-statement:
   while ( expression ) statement
   [...]
Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
  • The C Standard does not define *conditional statement* either, but it does use the term *controlling expression* for the selection and iterating statements, which does not make them *controlling statements*. – chqrlie Sep 12 '20 at 11:27
3

The question your friend was asked is fundamentally broken, since C defines no such thing as "control statements". Even if it did, my intuition is that it ought to cover all of those keywords.

Therefore, trying to analyse what does and does not fall under that umbrella is a fool's errand.

Given that they expected #1 to be the correct answer, it seems like they meant selection statements, i.e. "conditionals" as you say. while, break and continue clearly do not fall into that category.

You can read about all the different kinds of statements under §6.8 in C99 (or its equivalent in other versions).

Frankly, I'd go work for a different bank after being given that mess.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
0

(The definition of the different "statement-types" of your question seem a little bit problematic. Practically I had to estimate them from the question and not understanding your question based on the exact meaning of the "control" and "conditional" statements.)

No. Control statement is what changes the flow of the execution of your program.

Conditional statements are which do this based on a condition.

I think the correct answer had been (4).

peterh
  • 11,875
  • 18
  • 85
  • 108
0

Control Statement are the statements which get execute repetitively until the loop doesn't get terminated. Repetitively means once the statement block executes then it will get back to loop to check the condition. Due to repetition, it is said to be a Control Statement.

example:

for(i=0;i<=5;i++)
{
  COUT<<"THIS IS CONTROL STATEMENT";
}

Conditional Statements are the statements which will get executed once and it is not repetitive like a for loop. It will not check the loop condition again after it gets execute.

example:

 int i = 5;
 if(i==5)
 {
   COUT<<"THIS IS CONDITIONAL STATEMENT";
 }

if,if...else,switch are the conditional statements whereas for,while,do...while are the control statements.

Yasar Khan
  • 19
  • 3
  • The C Standard neither defines nor uses the terms *conditional statements* or *control statements*. This makes the question invalid. Other standards, specifying other languages use these terms for selection-, iterative- and sometime jump-statements. By your definition of *control statement*, and the examples provided in C++, none of the answers in the question are correct. – chqrlie Sep 12 '20 at 11:39
0

According to Java Docs, there are 2 types of Control Flow Statements:

  • conditional (if/else; switch);
  • iterative (for; do-while; while);
  • branching statements(conditional inside iterative or vice versa)

Both Control Flow Statements involve conditions, but the process of execution is different. Each type is utilised for specific routines.

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/flow.html

Updated:

C is using another methodology when it comes to statements https://learn.microsoft.com/en-us/cpp/c-language/statements-c?view=vs-2019

I find it easy to combine the knowledge from Java to understand C, maybe the OP will find it as well

luigi dota
  • 21
  • 3
  • Interesting: neither the C Standard, nor the [Microsoft C documentation](https://www.google.com/search?q=%22control+statements%22+site%3Alearn.microsoft.com%2Fen-us%2Fcpp%2Fc-language&oq=%22control+statements%22+site%3Alearn.microsoft.com%2Fen-us%2Fcpp%2Fc-language&aqs=chrome..69i57.17434j0j4&sourceid=chrome&ie=UTF-8) use the term *control statement*. – chqrlie Sep 12 '20 at 11:49