Computer Programming Flashcards
Sequential Structure
Executes a sequence of statements in order.
Control structure
Provides alternatives to sequential program and are used to alter the flow of execution
2 control structures
Selection structure
Repetition Structure
Selection structure
The program executes partical statements depending on the given condition. This alters the flow of program by making a selection or choice.
Repetition Structure
The program repeats statement a certain number of times, depending on the given condition. This alters the fliw of program execution by the repetition of one or more statements.
One way selection
If
If…else
switch statement
If and If…else statements
Used to create one-way, two-way and multiple selections
Switch Statement
is used to test a single variablr against a series of values.
The syntax for If statement
int score = 70;
if (score >= 60 ) {
System.out.printlb(“The student passed!”);
}
The Two-way selection
Used to choose between (2) alternatives. The if…else statement is used to implement two-way selections in Java.
The syntax for If…else statement
if ( score >=60)
{
System.out.println(“The student passed!”);
}
else
{
System.out.println(“The student failed!”);
}
Compound statements or Block statements
These are any kinfdof statements grouped together within curly braces.
Syntax for compound Statement
if (price => 500.00) {
discount = price * 0.10;
salePrice = price - discount;
System.out.println(“The discounted price is “ + salePrice);
}
else {
System.out.println(“No discount!”);
System.out.println(“The price is “ + price”);
}
Multiple Selections
When one control statement, either selection or repetition is located within another, it is said to be nested.
Nested if statement
allows a program to perform multiple selections