> For the complete documentation index, see [llms.txt](https://abhyas-kanaujia.gitbook.io/lb-dsa-notes-and-homework-abhyas/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://abhyas-kanaujia.gitbook.io/lb-dsa-notes-and-homework-abhyas/03-programming-basics-ii/homework/09.-break-and-continue-mcq.md).

# 09. Break and Continue MCQ

#### break/continue Question 1

```cpp
int a = 0, i = 0, b;
for (i = 0;i < 5; i++)
{
    a++;
    continue;
}

printf("%d", a);
```

<details>

<summary>Solution</summary>

There is no statement after `continue`. So its presence makes no difference. It would work just like a normal `for` loop.

The value of `a` and `i` changes similarly.

`a` value after the loop is its value at the last iteration i.e. when `i = 4`; loop breaks at `i = 5`. In the last iteration `a = 5`.

```
OUTPUT:
  5
```

</details>

#### break/continue Question 2

```cpp
int a = 0, i = 0, b;
for (i = 0;i < 5; i++)
{
  a++;
  if (i == 3)
    break;
}

print("%d", a);
```

<details>

<summary>Solution</summary>

The `for` loop runs until `i` is 3; after that it breaks out of the loop.

```
4
```

</details>

#### break/continue Question 3

```cpp
int i = 0, j = 0;
for (i = 0;i < 5; i++)
{
  for (j = 0;j < 4; j++)
    if (i > 1)
      break;
  printf("Hi \n");
}
```

<details>

<summary>Solution</summary>

The `i` loop runs for i in {0, 1, 2, 3, 4}. The `j` loops runs for j in {0, 1, 2, 3}. The loop doesn't impact how many times hi is printed.

The `break` statement only breaks the `j` loop which does not stops the `i` loop from printing "Hi".

So "Hi" is printed as many times as `i` loop runs; 5 times.

```
OUTPUT:
  Hi
  Hi
  Hi
  Hi
  Hi
```

</details>

#### break/continue Question 4

```cpp
int i = 0;
for (i = 0;i < 5; i++)
  if (i < 4)
  {
    printf("Hello");
    break;
  }
```

<details>

<summary>Solution</summary>

The `i` loop runs for i in {0, 1, 2, 3, 4}.

As soon as the `if` statement is `true`. It prints "Hello" and breaks out of the `i` loop.

The `if` statement is `true` in the first iteration i.e. `i = 0`.

So "Hello" is printed only once.

```
OUTPUT:
  Hello
```

</details>
