LESSON 1 Flashcards

(15 cards)

1
Q

It allows us to execute a statement or group of statements multiple times and on the side is the general form of a __ statement in most of the programming
languages.

A

Loop

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

Parts of Loop

A

Initialization
Condition
Change of State
Statement

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

It is used to execute a statement or a
group of statements repeatedly as
long as the supplied condition is true.

A

Iteration Statement

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

A statement in Java programming language repeatedly executes a target statement as long as a given condition is true. Is used to iterate a part of the program several times. If the number of iteration is not fixed, it is recommended to use ___.

A

While Loop

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

While Loop syntax:

A

Syntax:
Initialization;
while(Condition) {
Statements;
Change of State;
}

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

While loop syntax example:
Output:
1
2
3
4
5

A

class Main {
public static void main(String[] args) {
// declare variables
int i = 1, n = 5;
// while loop from 1 to 5
while(i <= n) {
System.out.println(i);
i++;
}
}
}

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

A ___ is similar to a while loop, except that a ___is guaranteed to execute at least one time. The Java is used to iterate a part of the program several times. Use it if the number of iteration is not fixed and you must have to execute the loop at least once.

A

Do While Loop

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

Do while syntax:

A

Initialization;
do {
Statements;
Change of state;
}while(Condition);

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

Do while syntax example:

A

import java.util.Scanner;
class Main {
public static void main(String[] args) {
int i = 1, n = 5;
// do…while loop from 1 to 5
do {
System.out.println(i);
i++;
} while(i <= n);
}
}

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

Java __ is used to run a block of code for a certain number of times. The Java ___is used to iterate a part of the program several times. If the number of iteration is fixed, it is recommended to use .

A

For Loop

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

For loop syntax:

A

for(initialization; Condition; ChangeOfState)
{
// Statements
}

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

For loop syntax example:
Program to print a text 5 times

A

class Main {
public static void main(String[] args) {
int n = 5;
// for loop
for (int i = 1; i <= n; ++i) {
System.out.println(“Java is fun”);
}
}
}

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

If a loop exists inside the body of
another loop, it’s called a __

A

Nested loop

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

Nested loop syntax:

A

// outer loop
for (int i = 1; i <= 5; ++i) {
// codes
// inner loop
for(int j = 1; j <=2; ++j) {
// codes
}
}

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

Nested loop syntax example:

A

public class Main {
public static void main(String[] args) {
int rows = 5;
// outer loop
for (int i = 1; i <= rows; ++i) {
// inner loop to print the numbers
for (int j = 1; j <= i; ++j) {
System.out.print(j + “ “);
}
System.out.println(“”);
}
}
}

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