Class 11: Loops Flashcards

1
Q

When is break statement valid?

A

In a loop or switch construct

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When is continue valid?

A

Only valid is loop contruct

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does break do

A

Exits innermost loop or switch statement which encloses it regardless of loop conditions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Continue what does it do

A

Causes the loop to stop its current iteration and begin to execute from the top again

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Go to (jump statement)

A

Go to identifier; //identifier is called a label here
Identifier: statement;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Dangling else

A

The compiler does not pay attention to formatting, so even if the else is aligned with the first if, the compiler pairs it with the SECOND IF

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Boolean issues

A

Int I; if(I) is better represented as if(I != 0)
Float x; if(!x) is better represented as if (x == 0.0)
Char c; if (c) is buffer represented as if(c != ‘\0’);
Int ptr; if (ptr) is better represented as if(*ptr != NULL)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to write an infinite loop

A

For(;;)
While(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The common operators

A

Examples
I = a,b,c; //stores a into I
I = (a,b,c); //stores c into I

For loop
For(n = 1,m=10; n <=m; n++, m—)

WHile(c = getchar(), c != ‘\0’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Enumerated data types

A

An enumerated data type is designed for variables that contain only a limited set of values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

EnumContainer_type = {CUP = 8; PINT = 16, Quart = 32, HALF_GALLON = 64, GALLON = 128};
Enum Container_Type milk_bottle;

A

Otherwise, but default CUP = 0, PINT = 1….

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Can you do this
Enum{CUP, PINT QUART, HALF_GALLON, GALLON}milk_bottle, gas_can, medicine_bottle;

A

Yes, if ther is only one declaration of the variables of a particular enumerated type, not Enum data type name, both statement may be combined. However no more variables of this enum data type can be declared later because not enum data type was given to it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Enum month{ Jan = 1;, feb = 2, mar = 3, apr = 4, may = 5, jun = 6, July = 7, aug = 8, sep = 9, oct = 10, nov = 11, dec = 12}this_month;

A

This_month = feb;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly