Computer Programming 4

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/50

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

51 Terms

1
New cards

Simple Statements

a simple instruction that ends with asemicolon

2
New cards

Compound Statements

several instructions that aregrouped into block enclosed in braces ({ })

3
New cards

Selection Statements

check certain conditions before executing a set ofstatements.provide the branching mechanism which allows aprogram to choose from alternatives

4
New cards

- if statement

if-else statement

conditional operator

swich statement

examples of selection statements

5
New cards

if statement

used for single selection.

the statement will beexecuted if and only if theexpression evaluates to true.

6
New cards

if-else statement

The else keyword is used when there are two possible coursesof action after an if statement.

7
New cards

conditional operator

written as ?:, is a ternary operator,which means that it takes three argumentsThe general syntax is:

8
New cards

break

separates the execution of statement per labeed case so that these is no "fall through" into the other statements

9
New cards

default

executed when expression does not evaluate to any of the listed constans in the case section

10
New cards

Repetition Statements

In looping, a sequence of statements is executed until some condition is satisfied which is placed for termination of theloop.

11
New cards

body of the loop

control statement

A program loop consists of two segments

12
New cards

entry controlled loop (pretest loop)

where the conditions are tested first and if satisfied then only the body of loop is executed.

13
New cards

exit controlled loop (post test loop)

where the test ismade at the end of the body, so the body is executed unconditionally first time

14
New cards

- while loop

- do while loop

-for loop

looping can of the following form

15
New cards

while loop

entry controlled loop statement

16
New cards

while loop

loop control variable must be: (1) initialized, (2)tested, and (3) updated for the loop to execute correctly

17
New cards

initialize

variable is usually set to a starting value beforethe while statement is reached

18
New cards

test

variable is tested before the start of each loop repetition

19
New cards

update

variable is updated within the body of the whileloop during each execution or pass

20
New cards

do while

exit controlled loop

21
New cards

for loop

an entry-controlled loop thatprovides a more concise loop control structure.

22
New cards

for loop

allows the user to efficiently write a loop that needs to be executed for a specific number of times

23
New cards

initialization

Executed first and only once. Allows the user to declare and initialize anyloop control variables

24
New cards

test condition

If met, the body of the loop is executed. Otherwise, the flow of control jumps to the next statement after the loop

25
New cards

increment/decrement

Step size; after the body of the for loop is executed, it checks the step size of the iterations.

26
New cards

More than one variable can be initialized at a time in the for statement

for (p=1,n=0; n<18; ++n)

27
New cards

It is also permissible to use expressions in the assignment statements ofinitialization and increment sections.

for (w = (a+b); w>0; w=w/2) //is valid

28
New cards

Like the initialization section, the increment section may also havemore than one part.

for (a=2,b=30; n <= m; n=n+1,m=m-1)

{ p = b/a;

cout << p << endl;

}

29
New cards

Empty for loop is possible

int i = 0, max = 3;

for ( ; ; )

{ if ( i < max)

{ cout<<"Hello!\n";i++;

}

else

break;

}

30
New cards

Declare loop control variable inside the for

int sum = 0, fact = 1;

for ( int i = 1; i<=5 ; i++ )

{

sum += i; // i is known throughout the loop

fact *= i;

}

31
New cards

while

This is a good, solid looping process with applications to numerous situations

32
New cards

do-while

This is a good choice when you are asking a question, whose answer will determine if the loop is repeated

33
New cards

for

This is a good choice when the number of repetitions is known or can be supplied by the user

34
New cards

counter controlled loop

used to read in and process a sequence of data items when you know in advance the number of items to be read.

35
New cards

Sentinel Controlled Loop

the user enters a "unique" data value, called a sentinel value, after the last data item; the loop repetition condition tests each data item and causes the loop to exit when the sentinel value is read.

36
New cards

return 0;

It is possible to end a program (or function) prior toi ts normal termination by using an "extra" return 0; statement.

37
New cards

return 0;

The drawback to this strategy is that it ends the entire program (or function) at the point where the return 0; statement is placed.

38
New cards

exit ()

It requires the Standard Library header file, stdlib.

39
New cards

exit (value)

format for exit ()

40
New cards

break;

Gets you out of a loop.

41
New cards

break;

The program continues with the next statementimmediately following the loop.

42
New cards

True

Break does not break out of a "nested loop"

43
New cards

continue;

performs a "jump" to the next test condition in a loop

44
New cards

True

The continue statement may be used ONLY in iterationstatements (loops). It serves to bypass, or jump over,certain iteration sections of a loop. continue;

45
New cards

Zero Iteration Loop

There may be instances where thewhile loop will not execute because the test failed (False condition).

46
New cards

Flag Controlled Loop

control theexecution of a loop

47
New cards

Flag Controlled Loop

type of boolen

48
New cards

Falg Controlled Loop

the value of the loop is initialized

49
New cards

Nested Loop

placing of one loop inside the body of another loop

50
New cards

Nested Loop

most commonly used in for loops

51
New cards

True

When working with nested loops, the outer loop changes onlyafter the inner loop is completely finished (or is interrupted).