presentation on powerpoint template.pptx

farantouqeer8 14 views 11 slides May 26, 2024
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

i have no words to tell you


Slide Content

Repetition statement and its execution Submitted by : Group no. 1 Sallal jaffar 1014 M.Sharjeel 1034 Zainab 5017 Azeema Hareem 1010

Outline Repetition statements Types While Statement Do while Statement For statement Importance & uses Execution of a repetition statement Process

Repetition statement Repetition statement (or loop) a block of code to be executed for a fixed number of times or until a certain condition met. OR Repetitive statements, also known as loops or iteration structures, are programming constructs that allow executing a block of code repeatedly based on a condition or a fixed number of iterations. Repetition statements are called loops, and are used to repeat the same code mulitple times in succession. The number of repetitions is based on criteria defined in the loop structure, usually a true/false expression.

Types Here are three types of a repetition statement as below; While statement Do while statement For statement

While The while statement evaluates expression/condition, which must return a boolean value. If the expression/condition is true, statement(s) in the while block is/are executed. Syntax: while (expression/condition)Statement(s) It continues testing the expression/condition and executing its block until the expression/condition evaluates to false. Example int i =1; while ( i <5) { System.out.print ( i + “”); i ++; } Output? 1234

Do while statement It is similar to while loops except it first executes the statement(s) inside the loop, and then evaluates the expression/condition. If the expression is true, the statement(s) in the do loop is/are executed again. Syntax do statement (s) ; While (expression) ; It continues executing the statement until the expression/condition becomes false. Note that the statement within the do loop is always executed at least once. Example int i =0; do { System.out.print ( i + “” i ++; } while( i <=3); Output 0 1 2 3 4

For statement Usually used when a loop will be executed a set number of times. Syntax for (initial statement; loop condition; update statement) statement(s); The for loop executes as follow: The initial statement is executed. The loop expression/condition is evaluated. If it is TRUE, the loop statement is executed followed by the execution of the update statement Repeat step 2, until the loop condition evaluates to FALSE Example for ( i =1; i <5; i ++) System.out.print ( i );

Importance & uses Importance Allow automating repetitive tasks. Improve code readability and Maintainability. Reduce redundancy in code. Uses Processing elements of a list or array. Iterating over database records. Implementing game loops Performing calculations until a condition is met. Consideration Ensure proper termination conditions to prevent infinite loops. Optimize loop structures for performance, especially in large-scale applications Repetitive statements are fundamental to programming and enable efficient automation of tasks requiring repeated execution.

Execution of repetitive statement Repetitive statements such as loops follow a specific execution process as below; Initialization Before the loop begins, any necessary variables are initialized. - This step prepares the loop for execution. Condition checking The loop checks a condition before each iteration to determine whether to continue or exit. - If the condition is true, the loop body executes. If false, the loop terminates. Execution of loop body The block of code within the loop body is executed. - This block may contain various instructions, calculations, or operations. Update variable Inside the loop body, variables may be updated to control the loop's behavior. - This step ensures progress towards the loop's termination condition.

Continue.. Repeat After executing the loop body, the loop returns to the condition checking phase. - If the condition is still true, the process repeats. Otherwise, the loop exits. Termination The loop terminates when the condition evaluates to false. - At this point, control passes to the next statement following the loop.
Tags