Understanding Loops Using C Language Week 15 Mr.Omer Salih.

Slides:



Advertisements
Similar presentations
Algorithm & Flow Charts Decision Making and Looping Presented By Manesh T Course:1090 CS.
Advertisements

© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Control Structures for Loops.
D EVELOPING P ROGRAMS USING ALGORITHMS AND FLOW CHARTS AND VICE VERSA Week 14 Mr.Mohammed Rahmath.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Some loop programs 1: Read in 10 integers and output their sum
Guidelines for working with Microsoft Visual Studio.Net.
Guidelines for working with Microsoft Visual Studio 6.
Basic Input/Output and Variables Ethan Cerami New York
If () else statement, switch statement, while () loop, do…while() loop and for( ; ; ) loop 1.
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Recursion Examples Fundamentals of CS Case 1: Code /* Recursion: Case 1 */ #include void count (int index); main () { count (0); getchar(); } void count.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
Do-while loop Syntax do statement while (loop repetition condition)
A First C Program /* Print a Message */ #include main() { printf("This is a test!\n"); } The program is compiled and run as cc pg32.c  a.out  This is.
1 Flowchart notation and loops Implementation of loops in C –while loops –do-while loops –for loops Auxiliary Statements used inside the loops –break –continue.
Previously Repetition Structures While, Do-While, For.
Chapter 4 Loops Write code that prints out the numbers Very often, we want to repeat a (group of) statement(s). In C++, we have 3 major ways of.
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
1. Agenda for loop Short-handed notation How to use break and continue 2.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
CMSC 104, Lecture 171 More Loops Topics l Counter-Controlled (Definite) Repetition l Event-Controlled (Indefinite) Repetition l for Loops l do-while Loops.
C Programming Lecture 7 : Control Structures. Control Structures Conditional statement : if, switch Determine a block of statements to execute depending.
Control Statements in C 1.Decision making statements 2.Looping statements 3.Branching statements
Looping Construct or Statements. Introduction of looping constructs In looping,a sequence of statements are executed until some condition for termination.
Iterations Very Useful: Ability to repeat a block of code Example:
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Decision Making It is used to change the order of the program based on condition. Categories: – Sequential structure – Selection structure – Iteration.
CMSC 104, Version 9/011 More Loops Topics Counter-Controlled (Definite) Repetition Event-Controlled (Indefinite) Repetition for Loops do-while Loops Choosing.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Repetition Repetition allows you to repeat an operation or a series of operations many times. This is called looping and is one of the basic structured.
CMSC 1041 More Loops ‘for’ loops and ‘do-while’ loops.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
CISC105 – General Computer Science Class 4 – 06/14/2006.
Control structures in C by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
CC213 Programming Applications Week #2 2 Control Structures Control structures –control the flow of execution in a program or function. Three basic control.
1 ICS103 Programming in C Lecture 7: Repetition Structures.
Algorithm & Flow Charts Decision Making and Looping
BIL 104E Introduction to Scientific and Engineering Computing Lecture 6.
Module 6 – Decision Control Statements Objectives  Understands Increment/Decrement operators, Conditional and special operators in C  Understands significance.
Week 3.  TO PRINT NUMBERS FROM 1 TO 20  TO PRINT EVEN NUMBERS FROM 1 TO 20 2.
The Repetition control structure using while loop.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 10P. 1Winter Quarter Repetition Structures Lecture 10.
Chapter 9 Repetition.
Unit-1 Introduction to Java
Loops in Java.
Chapter 4 - Program Control
Week 4 – Repetition Structures / Loops
Week 4 – Chapter 3 Repetition.
Iteration statement while do-while
2008/10/22: Lecture 12 CMSC 104, Section 0101 John Y. Park
- Additional C Statements
Chapter 9 Control Structures.
2008/10/22: Lecture 12 CMSC 104, Section 0101 John Y. Park
Loops in C.
Program Control Topics While loop For loop Switch statement
REPETITION STATEMENTS
More Loops Topics Counter-Controlled (Definite) Repetition
Dale Roberts, Lecturer IUPUI
Chapter 4 - Program Control
More Loops Topics Counter-Controlled (Definite) Repetition
More Loops Topics Counter-Controlled (Definite) Repetition
More Loops Topics Counter-Controlled (Definite) Repetition
Department of Computer Science
Lec 6 Loop Statements Introduction to Computer Programming
More Loops Topics Counter-Controlled (Definite) Repetition
Week 3 – Repetition (ctd.)
More Loops Topics Counter-Controlled (Definite) Repetition
Control Structure គោលបំណងនៃមេរៀន អ្វីជា Control structure ?
Presentation transcript:

Understanding Loops Using C Language Week 15 Mr.Omer Salih

Loop For loop While loop Do-While loop Break and Continue Mr.Omer Salih

For loop Syntax: for ( variable initialization; condition; variable update ) { Code to execute while the condition is true } Mr.Omer Salih

Write a c program for printing 0-9 using for loop #include int main() { int x; for ( x = 0; x < 10; x++ ) { printf( "%d\n", x ); } getchar(); } Mr.Omer Salih

While loop Syntax: While( ) { } Mr.Omer Salih

Do-While loop Syntax: do { } while ( condition ); Mr.Omer Salih

C programs Q) Write a c program for addition of two numbers. #include int main() { int a, b, c; printf("Enter two numbers to add\n"); scanf("%d%d",&a,&b); c = a + b; printf("Sum of entered numbers = %d\n",c); return 0; } Mr.Omer Salih

C program to check odd or even using modulus operator #include main() { int n; printf("Enter an integer\n"); scanf("%d",&n); if ( n%2 == 0 ) printf("Even\n"); else printf("Odd\n"); return 0; } Mr.Omer Salih

Session 15 End Mr.Omer Salih