File Name: decision making and looping in c .zip
- Decision Making and Looping in c#
- Control Statements in C
- Decision Making & Looping Structure in C++
Decision Making and Looping in c#
Home Explore. Successfully reported this slideshow. We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime. Decision making and looping. Upcoming SlideShare. Like this presentation? Why not share!
Embed Size px. Start on. Show related SlideShares at end. WordPress Shortcode. Hossain Md Shakhawat , Ph. Published in: Education. Full Name Comment goes here. Are you sure you want to Yes No. Sharmila Devi. Bhumi Patel. Riya Ahuja. Show More. No Downloads. Views Total views. Actions Shares. No notes for slide.
Decision making and looping 1. Looping 3. It enable us to repeat a specific section of code or statement without the use of goto statements.
The control statement tests certain conditions and then directs the repeated execution of the statements contained in the body of the loop. Control Statement Body of the Loop 5. The entry controlled loop 2. The exit controlled loop. The counter controlled loop 2. The sentinel controlled loop 6. So in the case of an entry controlled loop, the condition is tested before the execution of the loop. For example, the for loop is an entry controlled loop. In the given figure, the structure of an entry controlled loop is shown.
Entry Controlled Loop- Flowchart 8. So, in the case of the exit controlled loops, the body of the loop gets execution without testing the given condition for the first time. Then the condition is tested. The structure of an exit controlled loop is given in the given figure. Exit Controlled Loop- Flowchart That means, in this case, the value of the variable which controls the execution of the loop is previously known. The control variable is known as counter.
The counter must be initialized, tested and updated properly for the desired loop operations. The number of times we want to execute the loop may be a constant or variable. In this case, the value of the control variable differs within a limitation and the execution can be terminated at any moment as the value of the variable is not controlled by the loop.
The control variable in this case is termed by sentinel variable. This is a sentinel controlled loop and here the variable num is a sentinel variable The given steps may come at any order depending on the type of the loop. Setting and initialization of a condition variable. Execution of the statements of the loop. Test for a specified value of the condition variable for execution of the loop.
Incrementing or updating the condition variable. The for statement 2. The do while statement 3. The while do statement If the condition is true the body of the loop is executed; otherwise the loop is terminated and the execution continues with the statement that immediately follows the loop. If the condition is satisfied again, then the body of the loop is executed again.
This process continues till the value of the control variable fails to satisfy the test condition. For example more than one variable can be initialized at a time in the for statement separated by a comma. However in such cases the semicolons separating the sections must remain. If the test condition is not present then the for statement behaves like a infinite loop.
Such loop can be broken using break and goto statement. If it requires a post-test loop then we can use only one loop that is do while loop. If it requires a pre- test loop then we have two choices for loop and while loop. Use for loop if the counter based control is necessary. Use while loop if the sentinel based control is required. The break and goto statements can be used to jump out of a loop. When the loops are nested, the break would only exit from the loop containing it.
That is the break will exit only a single loop. It is useful to provide branching within a loop. Another important use of goto is to exit from deeply nested loops when an error occurs. The test condition is evaluated and if the condition is true, then the body of the loop is executed. After execution of the body the test condition is once again evaluated and if it is true, the body is executed once again. On exit the program continues with the statement immediately following the body of the loop.
Such situations can be handled by using do while loop. Comparison of Loops No. Topics For loop While loop Do Before the loop. Before the loop or in the body of the loop. Before the body of the loop. After the body of the loop. After the first execution. Entry controlled loop.
Exit controlled loop. Kernighan, Dennis M. You just clipped your first slide! Clipping is a handy way to collect important slides you want to go back to later.
Now customize the name of a clipboard to store your clips. Visibility Others can see my Clipboard. Cancel Save.
Control Statements in C
Looping statement are the statements execute one or more statement repeatedly several number of times. In C programming language there are three types of loops; while, for and do-while. When you need to execute a block of code several number of times then you need to use looping concept in C language. Conditional statement executes only once in the program where as looping statements executes repeatedly several number of time. In While Loop in C First check the condition if condition is true then control goes inside the loop body other wise goes outside the body.
US01CBCA21 – Programming Fundamental Using C. BCA SEM I. V.P. & R.P.T.P. Science College, V V Nagar. Page | 1. Unit 3 – Decision making, Looping and.
Decision Making & Looping Structure in C++
During looping a set of statements are executed until some conditions for termination of the loop is encountered. A program loop therefore consists of two segments one known as body of the loop and other is the control statement. The control statement tests certain conditions and then directs the repeated execution of the statements contained in the body of the loop. In looping process in general would include the following four steps 1.
Conditional Statements in C programming are used to make decisions based on the conditions. Conditional statements execute sequentially when there is no condition around the statements. If you put some condition for a block of statements, the execution flow may change based on the result evaluated by the condition. This process is called decision making in 'C. If statement 2.
In C, the control flows from one instruction to the next instruction until now in all programs. This control flow from one command to the next is called sequential control flow. Nonetheless, in most C programs the programmer may want to skip instructions or repeat a set of instructions repeatedly when writing logic. This can be referred to as sequential control flow. The declarations in C let programmers make such decisions which are called decision-making or control declarations.
A normal program is not a sequential execution of expressions or statements one after the other. It will have certain conditions to be checked or it will have certain number of iterations. When we check for certain conditions to execute further then it called as decision statements.