Conditional Statements and Loops

¡Supera tus tareas y exámenes ahora con Quizwiz!

For loop

Allows efficiently written loop that needs to execute a specific number of times

Loop

Allows repeated execution of group statements

Condition of for loop

Evaluated each time the loop iterates. The loop executes until the condition is false

Increment/Decrement of for loop

Executes after each iteration of the loop

Initialization of for loop

Expression executes only once during the beginning of the loop

if statement

It the expression evaluates as true, the block code inside the if statement is executed. If the expression is found to be false, the first set of code after the end of the if statement is executed. Uses comparison operator.

While loop

Repeatedly executes a target statement as long as a given condition is true. If the expression is tested and the result is false, the loop body is skipped and the first statement after the while loop is executed.

switch statement

Tests a variable for equality against a list of values. Each value is called a case, and the variable being switched is checked for each case. When a case is evaluated, a break statement can be used and the switch terminates. If no break appears, the flow control will continue and each case will be evaluated until a break is reached.

Loop Control Statements

The break statement terminates the loop and transfers execution to the statement immediately following the loop. The continue statement causes the loop to skip the remainder of its body and then immediately retests its condition prior to reiterating.

Do/while loop

Unlike while loop, is guaranteed to execute at least one time

default case

Used in switch statement. Can be used to perform a task when none of the cases are matched.

else statement

executes a statement if 'if' statement evaluates as flase

Nested if statement

if-else statement inside another if-else statement

else-if statemet

used to check multiple conditions, alternative to if-else statement

Logical Operators

used to combine multiple conditions && --> and || --> or ! --> not


Conjuntos de estudio relacionados

2) Aggregate Demand & Aggregate Supply - ECO 202 (Exam #3)

View Set

Pharm Chapter 37 Drugs for viral infections

View Set

Software Engineering introduction

View Set

Chapter 14: Users, Groups, and Permissions

View Set