Loops and Branches Flashcards

1
Q

What are the comparison operators?

A

==

!=
>
>=
- $a is not equal to $b after type juggling.
- An integer less than, equal to, or greater than zero when $a is respectively less than, equal to, or greater than $b. Available as of PHP 7.
Null - The first operand from left to right that exists and is not NULL. NULL if no values are defined and not NULL. Available as of PHP 7.

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

What does ‘default’ do in a switch statement?

A

The default action executes if none of the other switch statements are true.

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

What happens if you do not include ‘break’ into your switch cases?

A

It will continue executing the statements of following cases.

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

What is the syntax of a “for” loop?

A

for( initialization; condition; increment ){ // block of commands; }

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

What is the difference between “while” and “do while” loops?

A

The “do while” loop will always execute at least one time because the condition comes after the command block, whereas the “while” loop condition occurs before the command block.

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

What are the ideal use cases for “for” loops and “while” loops?

A

The “while” loop is most useful when you have an unknown or variable number of items to loop through. The “for” loop is most useful when you have a fixed number.

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

What is the syntax of a “foreach” loop?

A
foreach($array as $key => value){
   // block of commands
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a “foreach” loop?

A

It is made specifically for use with arrays, to iterate through an array from beginning to end.

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

What is the “continue” command?

A

“Continue” is used to skip a block of code but continue inside a loop.

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

What is the “goto” command?

A

“Goto” is used to force a jump to a specific place in the program.

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